Browse Source

平均分精度问题

zhaops 5 years ago
parent
commit
9269d1b592
1 changed files with 60 additions and 232 deletions
  1. 60 232
      src/main/resources/mapper/HomePageMapper.xml

+ 60 - 232
src/main/resources/mapper/HomePageMapper.xml

@@ -144,8 +144,8 @@
         a.beh_dept_id as id,
         a.beh_dept_name as name,
         count(*) AS num,
-        round( sum( CAST(b.behospital_day_num AS DECIMAL ))/ count(*), 2 ) AS averageValue,
-        round( sum( CAST(b.behospital_day_num AS DECIMAL )), 2 ) AS totleValue
+        round( sum( CAST(b.behospital_day_num AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS averageValue,
+        round( sum( CAST(b.behospital_day_num AS DECIMAL ( 18, 2 ) )), 2 ) AS totleValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -175,8 +175,8 @@
         a.beh_dept_id as id,
         a.beh_dept_name as name,
         count(*) AS num,
-        round( sum( CAST(b.total_fee AS DECIMAL ))/ count(*), 2 ) AS averageValue,
-        round( sum( CAST(b.total_fee AS DECIMAL )), 2 ) AS totleValue
+        round( sum( CAST(b.total_fee AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS averageValue,
+        round( sum( CAST(b.total_fee AS DECIMAL ( 18, 2 ) )), 2 ) AS totleValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -202,113 +202,24 @@
 
     <!-- 按科室统计平均住院天数 (分页)-->
     <select id="getAverageDayNumPage" resultType="com.diagbot.dto.AverageStatisticsDTO">
-        SELECT
-        id,
-        NAME,
-        averageValue,
-        lastAverageValue,
-        lastYearAverageValue
-        FROM
-        (
-        SELECT
-        dept.id,
-        dept.NAME,
-        t1.averageValue,
-        t2.lastAverageValue,
-        t3.lastYearAverageValue
-        FROM
-        (
-        SELECT DISTINCT
-        id,
-        NAME
+        SELECT t1.*
         FROM
-        (
-        (
-        SELECT DISTINCT
-        a.beh_dept_id AS id,
-        a.beh_dept_name AS NAME
+        (SELECT
+        t.id,
+        t.NAME,
+        sum( t.averageValue ) AS averageValue,
+        sum( t.lastAverageValue ) AS lastAverageValue,
+        sum( t.lastYearAverageValue ) AS lastYearAverageValue
         FROM
-        med_behospital_info a,
-        med_home_page b
-        WHERE
-        a.hospital_id = b.hospital_id
-        AND a.behospital_code = b.behospital_code
-        AND a.is_deleted = 'N'
-        AND b.is_deleted = 'N'
-        <![CDATA[AND a.qc_type_id <>0 ]]>
-        <if test="filterPageByAverageVO.hospitalId != null and filterPageByAverageVO.hospitalId != ''">
-            AND a.hospital_id = #{filterPageByAverageVO.hospitalId}
-        </if>
-        <if test="filterPageByAverageVO.startDate != null and filterPageByAverageVO.startDate != ''">
-            <![CDATA[ and a.leave_hospital_date >= DATE(#{filterPageByAverageVO.startDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.endDate != null and filterPageByAverageVO.endDate != ''">
-            <![CDATA[AND a.leave_hospital_date < DATE(#{filterPageByAverageVO.endDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.name != null and filterPageByAverageVO.name != ''">
-            AND a.beh_dept_name like CONCAT('%', #{filterPageByAverageVO.name},'%')
-        </if>
-        ) UNION
         (
-        SELECT DISTINCT
-        a.beh_dept_id AS id,
-        a.beh_dept_name AS NAME
-        FROM
-        med_behospital_info a,
-        med_home_page b
-        WHERE
-        a.hospital_id = b.hospital_id
-        AND a.behospital_code = b.behospital_code
-        AND a.is_deleted = 'N'
-        AND b.is_deleted = 'N'
-        <![CDATA[AND a.qc_type_id <>0 ]]>
-        <if test="filterPageByAverageVO.hospitalId != null and filterPageByAverageVO.hospitalId != ''">
-            AND a.hospital_id = #{filterPageByAverageVO.hospitalId}
-        </if>
-        <if test="filterPageByAverageVO.lastStartDate != null and filterPageByAverageVO.lastStartDate != ''">
-            <![CDATA[ and a.leave_hospital_date >= DATE(#{filterPageByAverageVO.lastStartDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.lastEndDate != null and filterPageByAverageVO.lastEndDate != ''">
-            <![CDATA[AND a.leave_hospital_date < DATE(#{filterPageByAverageVO.lastEndDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.name != null and filterPageByAverageVO.name != ''">
-            AND a.beh_dept_name like CONCAT('%', #{filterPageByAverageVO.name},'%')
-        </if>
-        ) UNION
         (
-        SELECT DISTINCT
-        a.beh_dept_id AS id,
-        a.beh_dept_name AS NAME
-        FROM
-        med_behospital_info a,
-        med_home_page b
-        WHERE
-        a.hospital_id = b.hospital_id
-        AND a.behospital_code = b.behospital_code
-        AND a.is_deleted = 'N'
-        AND b.is_deleted = 'N'
-        <![CDATA[AND a.qc_type_id <>0 ]]>
-        <if test="filterPageByAverageVO.hospitalId != null and filterPageByAverageVO.hospitalId != ''">
-            AND a.hospital_id = #{filterPageByAverageVO.hospitalId}
-        </if>
-        <if test="filterPageByAverageVO.lastYearStartDate != null and filterPageByAverageVO.lastYearStartDate != ''">
-            <![CDATA[ and a.leave_hospital_date >= DATE(#{filterPageByAverageVO.lastYearStartDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.lastYearEndDate != null and filterPageByAverageVO.lastYearEndDate != ''">
-            <![CDATA[AND a.leave_hospital_date < DATE(#{filterPageByAverageVO.lastYearEndDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.name != null and filterPageByAverageVO.name != ''">
-            AND a.beh_dept_name like CONCAT('%', #{filterPageByAverageVO.name},'%')
-        </if>
-        ))dept1
-        ) dept
-        LEFT JOIN (
         SELECT
         a.beh_dept_id AS id,
         a.beh_dept_name AS NAME,
         count(*) AS num,
-        round( sum( CAST( b.behospital_day_num AS DECIMAL ))/ count(*), 2 ) AS averageValue,
-        round( sum( CAST( b.behospital_day_num AS DECIMAL )), 2 ) AS totleValue
+        round( sum( CAST( b.behospital_day_num AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS averageValue,
+        0 AS lastAverageValue,
+        0 AS lastYearAverageValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -333,15 +244,15 @@
         GROUP BY
         a.beh_dept_id,
         a.beh_dept_name
-        ) t1 ON dept.id = t1.id
-        AND dept.NAME = t1.
-        NAME LEFT JOIN (
+        ) UNION
+        (
         SELECT
         a.beh_dept_id AS id,
         a.beh_dept_name AS NAME,
         count(*) AS num,
-        round( sum( CAST( b.behospital_day_num AS DECIMAL ))/ count(*), 2 ) AS lastAverageValue,
-        round( sum( CAST( b.behospital_day_num AS DECIMAL )), 2 ) AS totleValue
+        0 AS averageValue,
+        round( sum( CAST( b.behospital_day_num AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS lastAverageValue,
+        0 AS lastYearAverageValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -366,15 +277,15 @@
         GROUP BY
         a.beh_dept_id,
         a.beh_dept_name
-        ) t2 ON dept.id = t2.id
-        AND dept.NAME = t2.
-        NAME LEFT JOIN (
+        ) UNION
+        (
         SELECT
         a.beh_dept_id AS id,
         a.beh_dept_name AS NAME,
         count(*) AS num,
-        round( sum( CAST( b.behospital_day_num AS DECIMAL ))/ count(*), 2 ) AS lastYearAverageValue,
-        round( sum( CAST( b.behospital_day_num AS DECIMAL )), 2 ) AS totleValue
+        0 AS averageValue,
+        0 AS lastAverageValue,
+        round( sum( CAST( b.behospital_day_num AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS lastYearAverageValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -399,124 +310,38 @@
         GROUP BY
         a.beh_dept_id,
         a.beh_dept_name
-        ) t3 ON dept.id = t3.id
-        AND dept.NAME = t3.NAME
+        )
+        ) t
+        GROUP BY
+        t.id,
+        t.NAME
         ORDER BY
-        t1.averageValue DESC,
-        t2.lastAverageValue DESC,
-        t3.lastYearAverageValue DESC
-        )t
+        t.averageValue DESC,
+        t.lastAverageValue DESC,
+        t.lastYearAverageValue DESC)
+        t1
     </select>
 
     <!-- 按科室统计平均费用(分页) -->
     <select id="getAverageFeePage"   resultType="com.diagbot.dto.AverageStatisticsDTO">
-        SELECT
-        id,
-        NAME,
-        averageValue,
-        lastAverageValue,
-        lastYearAverageValue
-        FROM
-        (
-        SELECT
-        dept.id,
-        dept.NAME,
-        t1.averageValue,
-        t2.lastAverageValue,
-        t3.lastYearAverageValue
-        FROM
-        (
-        SELECT DISTINCT
-        id,
-        NAME
+        SELECT t1.*
         FROM
-        (
-        (
-        SELECT DISTINCT
-        a.beh_dept_id AS id,
-        a.beh_dept_name AS NAME
+        (SELECT
+        t.id,
+        t.NAME,
+        sum( t.averageValue ) AS averageValue,
+        sum( t.lastAverageValue ) AS lastAverageValue,
+        sum( t.lastYearAverageValue ) AS lastYearAverageValue
         FROM
-        med_behospital_info a,
-        med_home_page b
-        WHERE
-        a.hospital_id = b.hospital_id
-        AND a.behospital_code = b.behospital_code
-        AND a.is_deleted = 'N'
-        AND b.is_deleted = 'N'
-        <![CDATA[AND a.qc_type_id <>0 ]]>
-        <if test="filterPageByAverageVO.hospitalId != null and filterPageByAverageVO.hospitalId != ''">
-            AND a.hospital_id = #{filterPageByAverageVO.hospitalId}
-        </if>
-        <if test="filterPageByAverageVO.startDate != null and filterPageByAverageVO.startDate != ''">
-            <![CDATA[ and a.leave_hospital_date >= DATE(#{filterPageByAverageVO.startDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.endDate != null and filterPageByAverageVO.endDate != ''">
-            <![CDATA[AND a.leave_hospital_date < DATE(#{filterPageByAverageVO.endDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.name != null and filterPageByAverageVO.name != ''">
-            AND a.beh_dept_name like CONCAT('%', #{filterPageByAverageVO.name},'%')
-        </if>
-        ) UNION
         (
-        SELECT DISTINCT
-        a.beh_dept_id AS id,
-        a.beh_dept_name AS NAME
-        FROM
-        med_behospital_info a,
-        med_home_page b
-        WHERE
-        a.hospital_id = b.hospital_id
-        AND a.behospital_code = b.behospital_code
-        AND a.is_deleted = 'N'
-        AND b.is_deleted = 'N'
-        <![CDATA[AND a.qc_type_id <>0 ]]>
-        <if test="filterPageByAverageVO.hospitalId != null and filterPageByAverageVO.hospitalId != ''">
-            AND a.hospital_id = #{filterPageByAverageVO.hospitalId}
-        </if>
-        <if test="filterPageByAverageVO.lastStartDate != null and filterPageByAverageVO.lastStartDate != ''">
-            <![CDATA[ and a.leave_hospital_date >= DATE(#{filterPageByAverageVO.lastStartDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.lastEndDate != null and filterPageByAverageVO.lastEndDate != ''">
-            <![CDATA[AND a.leave_hospital_date < DATE(#{filterPageByAverageVO.lastEndDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.name != null and filterPageByAverageVO.name != ''">
-            AND a.beh_dept_name like CONCAT('%', #{filterPageByAverageVO.name},'%')
-        </if>
-        ) UNION
         (
-        SELECT DISTINCT
-        a.beh_dept_id AS id,
-        a.beh_dept_name AS NAME
-        FROM
-        med_behospital_info a,
-        med_home_page b
-        WHERE
-        a.hospital_id = b.hospital_id
-        AND a.behospital_code = b.behospital_code
-        AND a.is_deleted = 'N'
-        AND b.is_deleted = 'N'
-        <![CDATA[AND a.qc_type_id <>0 ]]>
-        <if test="filterPageByAverageVO.hospitalId != null and filterPageByAverageVO.hospitalId != ''">
-            AND a.hospital_id = #{filterPageByAverageVO.hospitalId}
-        </if>
-        <if test="filterPageByAverageVO.lastYearStartDate != null and filterPageByAverageVO.lastYearStartDate != ''">
-            <![CDATA[ and a.leave_hospital_date >= DATE(#{filterPageByAverageVO.lastYearStartDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.lastYearEndDate != null and filterPageByAverageVO.lastYearEndDate != ''">
-            <![CDATA[AND a.leave_hospital_date < DATE(#{filterPageByAverageVO.lastYearEndDate})]]>
-        </if>
-        <if test="filterPageByAverageVO.name != null and filterPageByAverageVO.name != ''">
-            AND a.beh_dept_name like CONCAT('%', #{filterPageByAverageVO.name},'%')
-        </if>
-        ))dept1
-        ) dept
-        LEFT JOIN (
         SELECT
         a.beh_dept_id AS id,
         a.beh_dept_name AS NAME,
         count(*) AS num,
         round( sum( CAST( b.total_fee AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS averageValue,
-        round( sum( CAST( b.total_fee AS DECIMAL ( 18, 2 ) )), 2 ) AS totleValue
+        0 AS lastAverageValue,
+        0 AS lastYearAverageValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -541,15 +366,15 @@
         GROUP BY
         a.beh_dept_id,
         a.beh_dept_name
-        ) t1 ON dept.id = t1.id
-        AND dept.NAME = t1.
-        NAME LEFT JOIN (
+        ) UNION
+        (
         SELECT
         a.beh_dept_id AS id,
         a.beh_dept_name AS NAME,
         count(*) AS num,
+        0 AS averageValue,
         round( sum( CAST( b.total_fee AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS lastAverageValue,
-        round( sum( CAST( b.total_fee AS DECIMAL ( 18, 2 ) )), 2 ) AS totleValue
+        0 AS lastYearAverageValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -574,15 +399,15 @@
         GROUP BY
         a.beh_dept_id,
         a.beh_dept_name
-        ) t2 ON dept.id = t2.id
-        AND dept.NAME = t2.
-        NAME LEFT JOIN (
+        ) UNION
+        (
         SELECT
         a.beh_dept_id AS id,
         a.beh_dept_name AS NAME,
         count(*) AS num,
-        round( sum( CAST( b.total_fee AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS lastYearAverageValue,
-        round( sum( CAST( b.total_fee AS DECIMAL ( 18, 2 ) )), 2 ) AS totleValue
+        0 AS averageValue,
+        0 AS lastAverageValue,
+        round( sum( CAST( b.total_fee AS DECIMAL ( 18, 2 ) ))/ count(*), 2 ) AS lastYearAverageValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -607,12 +432,15 @@
         GROUP BY
         a.beh_dept_id,
         a.beh_dept_name
-        ) t3 ON dept.id = t3.id
-        AND dept.NAME = t3.NAME
+        )
+        ) t
+        GROUP BY
+        t.id,
+        t.NAME
         ORDER BY
-        t1.averageValue DESC,
-        t2.lastAverageValue DESC,
-        t3.lastYearAverageValue DESC
-        )t
+        t.averageValue DESC,
+        t.lastAverageValue DESC,
+        t.lastYearAverageValue DESC)
+        t1
     </select>
 </mapper>