question

jd0963 avatar image
jd0963 asked

Help with this query??

SELECT [Admission date], [Admission type], LEFT(Report.dbo.ufn_getage ([Date of birth], [Admission date], 4) Age FROM Serve_way.dbo.AllPatients WHERE [Admission Date] >= '01-feb-2015' AND [Admission Type] LIKE '%Emer%' I need to somehow count the number of people whos age [age] is between 65 and 74 as well as the number of people whos [age] is 75 and over? Can someone please help? Thank you
sqlqueryhelp2012
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
David Wimbush avatar image
David Wimbush answered
You can nest the query like this: select AgeGroup , count(*) from ( select case when Age between 64 and 74 then 'Age 64-74' when Age = 75 then 'Age 75' else 'Other' end as AgeGroup from ( SELECT [Admission date] , [Admission type] , LEFT(Report.dbo.ufn_getage ([Date of birth], [Admission date], 4) Age FROM Serve_way.dbo.AllPatients WHERE [Admission Date] >= '01-feb-2015' AND [Admission Type] LIKE '%Emer%' ) x ) y group by AgeGroup order by AgeGroup
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.