统计前天昨天今天的数据,按单位分组
统计前天昨天今天的数据,按单位分组
先查出单位,然后在与子查询进行外关联
Java代码
select * from
--查询出机构表中所有的机构
(SELECT DISTINCT dc.district_code,dc.id unit_id,dc.unit_name
FROM pc_base_unit dc) o
LEFT JOIN
--统计前天的数据
(SELECT dc.unit_id,
SUM(dc.OUTPATIENT_REGISTER) 门诊就诊登记,
SUM(dc.RECIPEL_DETAIL) 门诊处方明细,
SUM(dc.INHOSPITAL_REGISTER) 住院就诊登记,
SUM(dc.INHOSPITAL_DETAIL) 住院处方明细,
SUM(dc.BASEINFO) 档案基本信息
FROM pc_data_datacleancollect dc
WHERE to_char(dc.CLEAN_TIME,'yyyy-mm-dd') = to_char(SYSDATE-2,'yyyy-mm-dd')
GROUP BY dc.unit_id) a ON o.unit_id = a.unit_id
left join
(
--统计昨天的数据
SELECT dc.unit_id,
SUM(dc.OUTPATIENT_REGISTER) 门诊就诊登记,
SUM(dc.RECIPEL_DETAIL) 门诊处方明细,
SUM(dc.INHOSPITAL_REGISTER) 住院就诊登记,
SUM(dc.INHOSPITAL_DETAIL) 住院处方明细,
SUM(dc.BASEINFO) 档案基本信息
FROM pc_data_datacleancollect dc
WHERE to_char(dc.CLEAN_TIME,'yyyy-mm-dd') = to_char(SYSDATE-1,'yyyy-mm-dd')
GROUP BY dc.unit_id) b ON o.unit_id = b.unit_id
left join (
--统计今天的数据
SELECT dc.unit_id,
SUM(dc.OUTPATIENT_REGISTER) 门诊就诊登记,
SUM(dc.RECIPEL_DETAIL) 门诊处方明细,
SUM(dc.INHOSPITAL_REGISTER) 住院就诊登记,
SUM(dc.INHOSPITAL_DETAIL) 住院处方明细,
SUM(dc.BASEINFO) 档案基本信息
FROM pc_data_datacleancollect dc
WHERE to_char(dc.CLEAN_TIME,'yyyy-mm-dd') = to_char(SYSDATE,'yyyy-mm-dd')
GROUP BY dc.unit_id) c ON o.unit_id = c.unit_id