select
to_char(d.c_ss_date,'yyyy-mm-dd') 手术日期,
(case when d.c_ss_type in ('1','手术') then 1 else 0 end) 手术台次,
(case when d.c_ss_type in ('2','治疗性操作') then 1 else 0 end) 治疗性操作台次,
(case when d.c_ss_type in ('3','诊断性操作') then 1 else 0 end) 诊断性操作台次,
(case when d.c_ss_type in ('4','介入治疗') then 1 else 0 end) 介入治疗台次,
(case when d.c_ss_type in ('5','微创手术') then 1 else 0 end) 微创手术台次
from
MR_SY_MAIN B,MR_SY_MAIN_ZYXX C,MR_SY_SSXX D
where c.c_reg_id=d.c_bill_id
and b.c_reg_id=c.c_reg_id
and b.c_reg_id=d.c_bill_id
--and b.c_zyh='2119283'
and B.C_CHECKED >= 2
and c.c_out_date>=to_date('2021-11-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and c.c_out_date<=to_date('2021-11-30 23:59:59','yyyy-mm-dd hh24:mi:ss')
--and c.c_out_dept='61' --出院科室泌尿外科
and b.c_zyh='2119283'
group by to_char(d.c_ss_date,'yyyy-mm-dd'),d.c_ss_type
首先楼上说的distinct 应该不符合所有场景,从这个结构上来看,会有其他列数据不一样但日期一样的情况。
理论上来说,这玩意不应该直接求和,算2台么?表关联有问题导致有笛卡尔积数据重复?
如果关联有问题就先解决关联问题;
如果确定关联没问题,那就改成下面这样
select
to_char(d.c_ss_date,'yyyy-mm-dd') 手术日期,
sum(case when d.c_ss_type in ('1','手术') then 1 else 0 end) 手术台次,
sum(case when d.c_ss_type in ('2','治疗性操作') then 1 else 0 end) 治疗性操作台次,
sum(case when d.c_ss_type in ('3','诊断性操作') then 1 else 0 end) 诊断性操作台次,
sum(case when d.c_ss_type in ('4','介入治疗') then 1 else 0 end) 介入治疗台次,
sum(case when d.c_ss_type in ('5','微创手术') then 1 else 0 end) 微创手术台次
from
MR_SY_MAIN B,MR_SY_MAIN_ZYXX C,MR_SY_SSXX D
where c.c_reg_id=d.c_bill_id
and b.c_reg_id=c.c_reg_id
and b.c_reg_id=d.c_bill_id
--and b.c_zyh='2119283'
and B.C_CHECKED >= 2
and c.c_out_date>=to_date('2021-11-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and c.c_out_date<=to_date('2021-11-30 23:59:59','yyyy-mm-dd hh24:mi:ss')
--and c.c_out_dept='61' --出院科室泌尿外科
and b.c_zyh='2119283'
group by to_char(d.c_ss_date,'yyyy-mm-dd')
如果你确定无论关联出来多少台都只算1台的话,那就再对这些求和字段再写个case when ,大于0台算1台,否则为0台
在你的查询语句前面。加一句
select distinct '手术日期' from (这里是你的sql语句)
可以吗