我想将三个查询合并为三列。
我正在寻找这个输出:
DEPTNAME1 -----计数(不同的pat_id Q1 )-----计数(不同的pat_id Q2 )-----计数(不同的pat_id < strong> Q1 )/计数(不同的pat_id Q2 )
DEPTNAME2 -----计数(不同的pat_id Q1 )-----计数(不同的pat_id Q2 )-----计数(不同的pat_id < strong> Q1 )/计数(不同的pat_id Q2 )
ETC
我目前的Q1代码:
select DEP.DEPARTMENT_NAME,
count(distinct hsp.pat_id)
from pat_enc_hsp hsp
left outer join clarity_adt adt
on hsp.pat_enc_csn_id = adt.pat_enc_csn_id
left outer join clarity_dep dep
on ADT.DEPARTMENT_ID = dep.DEPARTMENT_ID
inner join patient pat
on hsp.PAT_ID = pat.PAT_ID
left outer join ip_flwsht_rec rec
on rec.INPATIENT_DATA_ID = hsp.INPATIENT_DATA_ID
left outer join ip_flwsht_meas meas
on rec.FSD_ID = meas.FSD_ID
left outer join ip_flo_gp_data
on meas.FLO_MEAS_ID = ip_flo_gp_data.FLO_MEAS_ID
where adt.department_id IN (1,2,3,4,5)
and (hsp.ed_disposition_c is null or hsp.ed_disposition_c not in ('5','6'))
and hsp.HOSP_ADMSN_TIME between TO_DATE ('08-10-2014 00:00:00', 'DD-MM-YYYY HH24:MI:SS') and TO_DATE ('08-10-2014 23:59:59', 'DD-MM-YYYY HH24:MI:SS')
GROUP BY DEP.DEPARTMENT_NAME
我目前的Q2代码:
select DEP.DEPARTMENT_NAME,
count(distinct hsp.pat_id)
from pat_enc_hsp hsp
left outer join clarity_adt adt
on hsp.pat_enc_csn_id = adt.pat_enc_csn_id
left outer join clarity_dep dep
on ADT.DEPARTMENT_ID = dep.DEPARTMENT_ID
inner join patient pat
on hsp.PAT_ID = pat.PAT_ID
left outer join ip_flwsht_rec rec
on rec.INPATIENT_DATA_ID = hsp.INPATIENT_DATA_ID
left outer join ip_flwsht_meas meas
on rec.FSD_ID = meas.FSD_ID
left outer join ip_flo_gp_data
on meas.FLO_MEAS_ID = ip_flo_gp_data.FLO_MEAS_ID
where adt.department_id IN (1,2,3,4,5)
and (hsp.ed_disposition_c is null or hsp.ed_disposition_c not in ('5','6'))
and hsp.HOSP_ADMSN_TIME between TO_DATE ('08-10-2014 00:00:00', 'DD-MM-YYYY HH24:MI:SS') and TO_DATE ('08-10-2014 23:59:59', 'DD-MM-YYYY HH24:MI:SS')
and meas.flo_meas_id in ('00',
'7',
'8',
'9',
'0')
GROUP BY DEP.DEPARTMENT_NAME
Q3 从特定行Q1输出/从特定行Q2输出:
感谢您的帮助
答案 0 :(得分:0)
select DEPARTMENT_NAME, q1, q2, decode(q2, 0, null, q1 / q2) from
(select DEP.DEPARTMENT_NAME,
count(distinct hsp.pat_id) q1,
count(distinct case when meas.flo_meas_id in ('00', '7', '8', '9', '0') then hsp.pat_id else NULL end) q2
from pat_enc_hsp hsp
left outer join clarity_adt adt on hsp.pat_enc_csn_id = adt.pat_enc_csn_id
left outer join clarity_dep dep on ADT.DEPARTMENT_ID = dep.DEPARTMENT_ID
inner join patient pat on hsp.PAT_ID = pat.PAT_ID
left outer join ip_flwsht_rec rec on rec.INPATIENT_DATA_ID = hsp.INPATIENT_DATA_ID
left outer join ip_flwsht_meas meas on rec.FSD_ID = meas.FSD_ID
left outer join ip_flo_gp_data on meas.FLO_MEAS_ID = ip_flo_gp_data.FLO_MEAS_ID
where adt.department_id IN (1,2,3,4,5)
and (hsp.ed_disposition_c is null or hsp.ed_disposition_c not in ('5','6'))
and hsp.HOSP_ADMSN_TIME between TO_DATE ('08-10-2014 00:00:00', 'DD-MM-YYYY HH24:MI:SS') and TO_DATE ('08-10-2014 23:59:59', 'DD-MM-YYYY HH24:MI:SS')
GROUP BY DEP.DEPARTMENT_NAME);