Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

CTE Total count

$
0
0

Hi i have this query

SELECT      TriageToDoctor, DoctorToBedRequest, BedRequestToDepart,DepartureDate
FROM           EmergencyDepartment
WHERE DepartureDate  >=DATEADD(day, -28, GETDATE()) and DepartureMethod ='Admitted'
Group BY  TriageToDoctor, DoctorToBedRequest, BedRequestToDepart,DepartureDate
)
Select *
                         ,CASE WHEN DepartureDate>=DATEADD(Day,-1,GETDATE())then 'RunDate' else '' END AS '<1Day'
                         ,CASE WHEN DepartureDate >=DATEADD(Day,-7,GETDATE()) Then '-7 Days' Else '' END AS '<7Days'
                         ,CASE WHEN DepartureDate >=DATEADD(DAy,-28,GETDATE()) THEN '-28 Days' ELSE '' END  AS '<28Days'
  FROM
	Base
GROUP BY TriageToDoctor, DoctorToBedRequest, BedRequestToDepart,DepartureDate
ORDER BY DepartureDate ASC
It produces this output

However i need to produce this result by as an average

How can i get this, thanks


David


Viewing all articles
Browse latest Browse all 23857

Trending Articles