Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Age grouping

Author  Topic 

abdbari
Starting Member

7 Posts

Posted - 2013-09-17 : 22:26:33
Please help me how to write a query to count AGE by category (Exec or non Exec)

sample are as follow:
----Age Group---------
Category: Age <25 age 25-35 age 45-50 Total
Exec 2 1 3
Non Exec 10 5 5 20

Grand total: 23
Thanks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-09-17 : 22:50:39
[code]
select category,
count(case when age < 25 then age end) as [Age < 25],
count(case when age >= 25 and age < 35 then age end) as [Age 25 - 35],
. . .
count(*) as Total
from yourtable
group by category
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

abdbari
Starting Member

7 Posts

Posted - 2013-09-17 : 23:34:25
Thanks will try it.
Go to Top of Page
   

- Advertisement -