Browse Source

sql优化

wangliang 2 years ago
parent
commit
52e575cbb4
1 changed files with 17 additions and 9 deletions
  1. 17 9
      themis-business/src/main/resources/mapper/TOeExamRecordMapper.xml

+ 17 - 9
themis-business/src/main/resources/mapper/TOeExamRecordMapper.xml

@@ -1461,8 +1461,11 @@
         t_e_exam_student tees
         join t_e_student tes on
         tees.student_id = tes.id
-        where
-        exists(
+        where 1 = 1
+        <if test="examId != null and examId != ''">
+            and tees.exam_id = #{examId}
+        </if>
+        and exists(
         select
         tee.id
         from
@@ -1483,7 +1486,6 @@
             <if test="courseCode != null and courseCode != ''">
                 and tees.course_code = #{courseCode}
             </if>
-            and tees.exam_id = tee.id
             and tes.org_id = tee.org_id
         </where>
         )
@@ -1492,8 +1494,11 @@
         count(distinct toer.exam_student_id) as c
         from
         t_oe_exam_record toer
-        where
-        exists (
+        where 1 = 1
+        <if test="examId != null and examId != ''">
+            and toer.exam_id = #{examId}
+        </if>
+        and exists (
         select
         *
         from
@@ -1504,13 +1509,16 @@
         t_e_exam_student tees
         join t_e_student tes on
         tees.student_id = tes.id
-        where
-        exists(
+        where 1 = 1
+        <if test="examId != null and examId != ''">
+            and tees.exam_id = #{examId}
+        </if>
+        and exists(
         select
         tee.id
         from
         t_e_exam tee
-        <where>1 = 1
+        <where> 1 = 1
             <if test="orgId != null and orgId != ''">
                 and tee.org_id = #{orgId}
             </if>
@@ -1526,7 +1534,7 @@
             <if test="courseCode != null and courseCode != ''">
                 and tees.course_code = #{courseCode}
             </if>
-            and tees.exam_id = tee.id
+            and tes.org_id = tee.org_id
         </where>
         )) t
         where