SQL 2005, I have a table with the column "age_c", I need to group records by age ranges. This is the query I found on this site and it gets me 90%, but "group by" is an error, * Invalid column name "age_range" *
select
case
when age_c <18 then 'Under 18'
when age_c between 18 and 24 then '18-24'
when age_c between 25 and 34then '25-34'
END as age_range,
Count(*) as count
from contacts
group by age_range
order by age_range
When I group and order "age_c", my result is:
Under 18 1
18-24 1
18-24 1
25-34 1
I want to:
Under 18 1
18-24 2
25-34 1
Thank.
source
share