Oracle 同一个字段的两值进行加减计算
如
病人ID 入院日期 出院日期
00001 2016-09-01 2016-09-10
00001 2016-09-15 2016-09-30
计算病人00001 是否10天内再次入院
select b.patient_id, trunc(b.admission_date_time)-trunc(d.discharge_date_time) from
(select a.patient_id ,a.visit_id,a.admission_date_time,a.discharge_date_time from pat_visit a where a.admission_date_time<to_date('2016-09-30','yyyy-mm-dd')+1 and a.admission_date_time>=to_date('2016-07-01','yyyy-mm-dd')) b
left join
(select c.patient_id ,c.visit_id,c.admission_date_time,c.discharge_date_time from pat_visit c) d
on b.patient_id=d.patient_id and b.visit_id=d.visit_id+1
left join operation e on d.patient_id=e.patient_id and d.visit_id=e.visit_id
where trunc(b.admission_date_time)-trunc(d.discharge_date_time)<30 ;