เอาใว้ดูย้อนหลัง
select visit_vn
,case when ( to_date(substring(t_visit.visit_staff_doctor_discharge_date_time,1,10),'YYYY-MM-DD') - to_date(substring(t_visit.visit_begin_admit_date_time ,1,10) ,'YYYY-MM-DD') ) > 0
then ( to_date(substring(t_visit.visit_staff_doctor_discharge_date_time,1,10),'YYYY-MM-DD') - to_date(substring(t_visit.visit_begin_admit_date_time ,1,10) ,'YYYY-MM-DD') )
else 1 end as day_stay
from t_visit
where visit_hn = '000080130' and f_visit_type_id = '1'
select visit_vn
,case when ( to_date(substring(t_visit.visit_staff_doctor_discharge_date_time,1,10),'YYYY-MM-DD') - to_date(substring(t_visit.visit_begin_admit_date_time ,1,10) ,'YYYY-MM-DD') ) > 0
then ( to_date(substring(t_visit.visit_staff_doctor_discharge_date_time,1,10),'YYYY-MM-DD') - to_date(substring(t_visit.visit_begin_admit_date_time ,1,10) ,'YYYY-MM-DD') )
else 1 end as day_stay
from t_visit
where visit_hn = '000080130' and f_visit_type_id = '1'