Browse Source

sql优化调整

chengyao 3 years ago
parent
commit
00e0f99728
1 changed files with 21 additions and 26 deletions
  1. 21 26
      src/main/resources/mapper/BehospitalInfoMapper.xml

+ 21 - 26
src/main/resources/mapper/BehospitalInfoMapper.xml

@@ -3386,23 +3386,23 @@
         t1.deptId,
         t1.deptName,
         t1.doctorId,
-        t2.entryNum,
-        t1.mrNum,
-        t1.totleValue,
-        t1.averageValue,
-        t1.firstLevelNum,
-        t1.secondLevelNum,
-        t1.firstLevelPercent,
-        t1.secondLevelPercent,
-        t1.firstLevelPercentStr,
-        t1.secondLevelPercentStr,
-        t2.emptyNum,
-        t2.errorNum,
-        t2.mrNum * t3.entryNum AS entryTotleNum,
-        ROUND( ( t2.mrNum * t3.entryNum  - t2.emptyNum ) / ( t2.mrNum * t3.entryNum ), 4 ) AS emptyPercent,
-        ROUND( ( t2.mrNum * t3.entryNum  - t2.errorNum ) / ( t2.mrNum * t3.entryNum ), 4 ) AS errorPercent,
-        CONCAT( ROUND( ( t2.mrNum * t3.entryNum - t2.emptyNum ) / ( t2.mrNum * t3.entryNum )* 100, 2 ), '%' ) AS emptyPercentStr,
-        CONCAT( ROUND( ( t2.mrNum * t3.entryNum - t2.errorNum ) / ( t2.mrNum * t3.entryNum )* 100, 2 ), '%' ) AS errorPercentStr
+        sum(t1.mrNum),
+        sum(t1.totleValue),
+        sum(t1.averageValue),
+        sum(t1.firstLevelNum),
+        sum(t1.secondLevelNum),
+        ROUND(sum(t1.firstLevelNum)/sum(t1.mrNum),4) as firstLevelPercent,
+        ROUND(sum(t1.secondLevelNum)/sum(t1.mrNum),4) as secondLevelPercent,
+        concat( ROUND( sum(t1.firstLevelNum)/sum(t1.mrNum)* 100, 2 ),'%' ) AS firstLevelPercentStr,
+        concat( ROUND( sum(t1.secondLevelNum)/sum(t1.mrNum)* 100, 2 ),'%' ) AS secondLevelPercentStr,
+        sum(t2.entryNum),
+        sum(t2.emptyNum),
+        sum(t2.errorNum),
+        sum(t2.mrNum) * t3.entryNum AS entryTotleNum,
+        ROUND( ( sum(t2.mrNum) * t3.entryNum  - sum(t2.emptyNum) ) / ( sum(t2.mrNum) * t3.entryNum ), 4 ) AS emptyPercent,
+        ROUND( ( sum(t2.mrNum) * t3.entryNum  - sum(t2.errorNum) ) / ( sum(t2.mrNum) * t3.entryNum ), 4 ) AS errorPercent,
+        CONCAT( ROUND( ( sum(t2.mrNum) * t3.entryNum - sum(t2.emptyNum) ) / ( sum(t2.mrNum) * t3.entryNum )* 100, 2 ), '%' ) AS emptyPercentStr,
+        CONCAT( ROUND( ( sum(t2.mrNum) * t3.entryNum - sum(t2.errorNum) ) / ( sum(t2.mrNum) * t3.entryNum )* 100, 2 ), '%' ) AS errorPercentStr
         FROM
         (
         SELECT
@@ -3421,11 +3421,7 @@
         ROUND( sum( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS totleValue,
         ROUND( avg( CAST( c.score_res AS DECIMAL ( 18, 2 )) ), 2 ) AS averageValue,
         count(case when c.`level` = '合格' then 1 end) AS firstLevelNum,
-        count(case when c.`level` = '不合格' then 1 end) AS secondLevelNum,
-        ROUND( count(case when c.`level` = '合格' then 1 end)/ count( * ), 4 ) AS firstLevelPercent,
-        ROUND(  count(case when c.`level` = '不合格' then 1 end)/ count( * ), 4 ) AS secondLevelPercent,
-        concat( ROUND( count(case when c.`level` = '合格' then 1 end)/ count( * )* 100, 2 ),'%' ) AS firstLevelPercentStr,
-        concat( ROUND(  count(case when c.`level` = '不合格' then 1 end)/ count( * )* 100, 2 ),'%' ) AS secondLevelPercentStr
+        count(case when c.`level` = '不合格' then 1 end) AS secondLevelNum
         FROM
         med_behospital_info a,
         med_qcresult_cases c
@@ -3466,7 +3462,6 @@
         </if>
         GROUP BY
         a.beh_dept_id,
-        a.beh_dept_name,
         a.doctor_id,
         a.director_doctor_id,
         a.beh_doctor_id
@@ -3537,7 +3532,6 @@
         </if>
         GROUP BY
         a.beh_dept_id,
-        a.beh_dept_name,
         a.doctor_id,
         a.director_doctor_id,
         a.beh_doctor_id
@@ -3553,7 +3547,9 @@
         WHERE
         t1.deptId = t2.deptId
         AND t1.deptName = t2.deptName
-        AND t1.doctorId = t2.doctorId)t4
+        AND t1.doctorId = t2.doctorId
+        group by t1.deptId,t1.doctorId
+        )t4
         left join bas_doctor_info bas
         on t4.doctorId = bas.doctor_id
         and bas.is_deleted = 'N'
@@ -3563,7 +3559,6 @@
         <if test="professor != null and professor != ''">
             and bas.professor = #{professor}
         </if>
-        group by t4.doctorId
     </select>