该 SQL 查询语句是用于在医院收费系统中查询指定时间范围内各费用项目在不同院区的总费用。其中,'sum(西药费)'、'sum(中成药费)'、'sum(中草药费)'、'sum(挂号费)'、'sum(床位费)'、'sum(诊疗费)'、'sum(检查费)'、'sum(治疗费)'、'sum(护理费)'、'sum(手术费)'、'sum(化验费)'、'sum(放射费)'、'sum(其他费)' 分别表示西药费、中成药费、中草药费、挂号费、床位费、诊疗费、检查费、治疗费、护理费、手术费、化验费、放射费和其他费用项目的总费用。'院区' 表示不同的医院院区。

整个 SQL 语句的作用是对各费用项目在不同院区的总费用进行汇总统计。

SQL 代码示例:

select sum(西药费) 西药费,
sum(中成药费) 中成药费,
sum(中草药费) 中草药费,
sum(挂号费) 挂号费,
sum(床位费) 床位费,
sum(诊疗费) 诊疗费,
sum(检查费) 检查费,
sum(治疗费) 治疗费,
sum(护理费) 护理费,
sum(手术费) 手术费,
sum(化验费) 化验费,
sum(放射费) 放射费,
sum(其他费) 其他费,
院区
from (
select nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '01',
                      t.tot_cost,
                      0)),
           0) 西药费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '02',
                      t.tot_cost,
                      0)),
           0) 中成药费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '03',
                      t.tot_cost,
                      0)),
           0) 中草药费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '04',
                      t.tot_cost,
                      0)),
           0) 挂号费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '05',
                      t.tot_cost,
                      0)),
           0) 床位费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '06',
                      t.tot_cost,
                      0)),
           0) 诊疗费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '07',
                      t.tot_cost,
                      0)),
           0) 检查费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '08',
                      t.tot_cost,
                      0)),
           0) 治疗费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '09',
                      t.tot_cost,
                      0)),
           0) 护理费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '10',
                      t.tot_cost,
                      0)),
           0) 手术费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '11',
                      t.tot_cost,
                      0)),
           0) 化验费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '12',
                      t.tot_cost,
                      0)),
           0) 放射费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '14',
                      t.tot_cost,
                      0)),
           0) 其他费,
DECODE(b.hospital_didt,'YLV21051','昆明医科大学第一附属医院','43120189-1-2','昆明医科大学第一附属医院呈贡医院') 院区
  from fin_ipb_feeinfo t,fin_ipr_inmaininfo b
 where t.balance_state = '0'
 AND t.inpatient_no=b.inpatient_no
   and t.fee_date >= to_date('2023-04-18 00:00:00','yyyy-mm-dd hh24:mi:ss')
   and t.fee_date <= to_date('2023-04-18 10:00:00','yyyy-mm-dd hh24:mi:ss')
   GROUP BY DECODE(b.hospital_didt,'YLV21051','昆明医科大学第一附属医院','43120189-1-2','昆明医科大学第一附属医院呈贡医院')
   union
   select nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '01',
                      t.tot_cost,
                      0)),
           0) 西药费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '02',
                      t.tot_cost,
                      0)),
           0) 中成药费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '03',
                      t.tot_cost,
                      0)),
           0) 中草药费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '04',
                      t.tot_cost,
                      0)),
           0) 挂号费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '05',
                      t.tot_cost,
                      0)),
           0) 床位费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '06',
                      t.tot_cost,
                      0)),
           0) 诊疗费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '07',
                      t.tot_cost,
                      0)),
           0) 检查费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '08',
                      t.tot_cost,
                      0)),
           0) 治疗费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '09',
                      t.tot_cost,
                      0)),
           0) 护理费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '10',
                      t.tot_cost,
                      0)),
           0) 手术费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '11',
                      t.tot_cost,
                      0)),
           0) 化验费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '12',
                      t.tot_cost,
                      0)),
           0) 放射费,
       nvl(sum(decode(fun_get_fee_stat_cate('ZY01', t.fee_code),
                      '14',
                      t.tot_cost,
                      0)),
           0) 其他费,
DECODE(b.hospital_didt,'YLV21051','昆明医科大学第一附属医院','43120189-1-2','昆明医科大学第一附属医院呈贡医院') 院区
  from fin_ipb_feeinfo t,fin_ipr_inmaininfo b
 where t.balance_state = '1'
  AND t.inpatient_no=b.inpatient_no
   and t.fee_date >= to_date('2023-04-18 00:00:00','yyyy-mm-dd hh24:mi:ss')
   and t.fee_date <= to_date('2023-04-18 10:00:00','yyyy-mm-dd hh24:mi:ss')
   and t.balance_date > to_date('2023-04-18 10:00:00','yyyy-mm-dd hh24:mi:ss')
GROUP BY DECODE(b.hospital_didt,'YLV21051','昆明医科大学第一附属医院','43120189-1-2','昆明医科大学第一附属医院呈贡医院'))
GROUP BY 院区

说明:

  • 该 SQL 语句包含两个子查询,分别查询结算状态为 '0' 和 '1' 的费用信息。
  • 使用 fun_get_fee_stat_cate 函数获取费用项目的类别,并使用 decode 函数将不同类别映射到不同的费用项目。
  • 使用 nvl 函数将 sum 函数的返回值设置为 0,避免出现空值。
  • 使用 to_date 函数将字符串类型的时间转换为日期类型。
  • 使用 group by 语句对不同的院区进行分组汇总。

希望这个解释对您有所帮助!

医院费用统计 SQL 查询语句详解 - 不同院区费用汇总

原文地址: https://www.cveoy.top/t/topic/nu8h 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录