Skip to content

SQL Median LOS Removal Year

clancyjane edited this page Sep 23, 2014 · 1 revision

This is an example of median los calculated using an entry cohort and calculating the median LOS through the current data warehouse cutoff date for ALL ENTRIES even if they did NOT exit. If they did not exit the cutoff_date is used. This is an EXAMPLE ONLY. You may NOT want to handle children who DID NOT EXIT in this manner.

select distinct 
	  Year(Removal_dt) [Removal Year]
	, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY dur_days) OVER (PARTITION BY Year(Removal_Dt)) [Median - dur_days]
from base.rptPlacement plc,ref_last_dw_transfer
where Year(Removal_dt)  between 2000 and (year(cutoff_date)-1)
order by Year(Removal_dt)

Clone this wiki locally