I have seen other group by alias examples. However I can't seem to make it work for my example.
I have a table with people info which I want to group by age categories. (20 - 25, 26 - 30, 31- 35, 36 -40 and >40)
Code I managed so far is:
select sub
from (
select Case
when Age <26 then'20-26'
when Age <31 then '26-30'
when Age < 36 then '31-35'
when Age <41 then '36-40'
else '>40'
end
from people
) as sub
Group by sub
I want to get the total number of people that belongs to each age group.