소스 검색

优化sql订单数量分析

Memory_LG 9 달 전
부모
커밋
687d0e5aa6
1개의 변경된 파일48개의 추가작업 그리고 2개의 파일을 삭제
  1. 48 2
      src/main/resources/mapper/housingconstruction/CenterdataTHousingconstructionViewMapper.xml

+ 48 - 2
src/main/resources/mapper/housingconstruction/CenterdataTHousingconstructionViewMapper.xml

@@ -22,8 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         GROUP BY a.id
     </select>
 
-    <select id="getOrderList" parameterType="CenterdataTHousingconstructionSteelcylinder" resultType="map">
-        SELECT concat(a.`month`,'月') `month`, IFNULL(b.num, 0) num
+        <!--SELECT concat(a.`month`,'月') `month`, IFNULL(b.num, 0) num
         FROM (SELECT 1 AS `month` UNION
               SELECT 2 AS `month` UNION
               SELECT 3 AS `month` UNION
@@ -49,6 +48,53 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             </if>
                   ${params.dataScope}
         GROUP BY MONTH( b.sign_time )) b on a.`month` = b.`month`
+        ORDER BY a.`month`-->
+    <select id="getOrderList" parameterType="CenterdataTHousingconstructionSteelcylinder" resultType="map">
+        SELECT
+            concat( a.`month`, '月' ) `month`,
+            IFNULL( b.num, 0 ) num
+        FROM (
+            SELECT 1 AS `month`
+            UNION
+            SELECT 2 AS `month`
+            UNION
+            SELECT 3 AS `month`
+            UNION
+            SELECT 4 AS `month`
+            UNION
+            SELECT 5 AS `month`
+            UNION
+            SELECT 6 AS `month`
+            UNION
+            SELECT 7 AS `month`
+            UNION
+            SELECT 8 AS `month`
+            UNION
+            SELECT 9 AS `month`
+            UNION
+            SELECT 10 AS `month`
+            UNION
+            SELECT 11 AS `month`
+            UNION
+            SELECT 12 AS `month`
+        ) a
+        LEFT JOIN (
+        SELECT a.`year_month`, sum( a.count ) AS num FROM (
+            SELECT MONTH ( sign_time ) AS `year_month`, steelcylinder_id, COUNT(*) AS count
+            FROM centerdata_t_housingconstruction_steelcylinder_log
+            WHERE YEAR ( sign_time ) = YEAR ( CURRENT_DATE )
+            AND steelcylinder_id IN (
+                SELECT id FROM centerdata_t_housingconstruction_steelcylinder a
+                <where>
+                    <if test="enterpriseId != null and enterpriseId != ''">
+                        and enterprise_id = #{enterpriseId}
+                    </if>
+                </where>
+            )
+            GROUP BY DATE_FORMAT( sign_time, '%Y-%m' ),steelcylinder_id
+            ORDER BY`year_month`, steelcylinder_id
+            ) a GROUP BY a.`year_month`
+        ) b ON a.`month` = b.`year_month`
         ORDER BY a.`month`
     </select>