如it
病人ID 入院日期 出院日期io
00001 2016-09-01 2016-09-10date
00001 2016-09-15 2016-09-30select
計算病人00001 是否10天內再次入院im
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 ; di