瀏覽代碼

sql查询优化

gaodm 6 年之前
父節點
當前提交
4f672644be
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      icss-service/src/main/resources/mapper/ModuleDetailMapper.xml

+ 11 - 3
icss-service/src/main/resources/mapper/ModuleDetailMapper.xml

@@ -22,8 +22,9 @@
 
 
     <select id="getDetailByModule" parameterType="java.util.Map" resultMap="BaseResultMap">
-        select  DISTINCT t1.* from
-        icss_module_detail t1 left join icss_question_info t2 on (t1.question_id = t2.id or t1.question_id is null)
+        select t3.* from
+        (select  DISTINCT t1.* from
+        icss_module_detail t1 left join icss_question_info t2 on t1.question_id = t2.id
         where t1.is_deleted = 'N' and t2.is_deleted = 'N'
         and t1.module_id in
         <foreach item="id" collection="ids" open="(" separator="," close=")">
@@ -36,7 +37,14 @@
             <![CDATA[ and t2.age_begin <= #{age} ]]>
             <![CDATA[ and t2.age_end >= #{age} ]]>
         </if>
-        order by t1.module_id, t1.order_no
+        union
+        select  DISTINCT t1.* from
+        icss_module_detail t1 where t1.question_id is null and  t1.is_deleted = 'N'
+        and t1.module_id in
+        <foreach item="id" collection="ids" open="(" separator="," close=")">
+            #{id}
+        </foreach>) t3
+        order by t3.module_id, t3.order_no
     </select>
 
 </mapper>