One might want to GROUP BY more than one column
declare @temp table(age int, name varchar(15))
insert into @temp
select 18, 'matt' union all
select 21, 'matt' union all
select 21, 'matt' union all
select 18, 'luke' union all
select 18, 'luke' union all
select 21, 'luke' union all
select 18, 'luke' union all
select 21, 'luke'
SELECT Age, Name, count(1) count
FROM @temp
GROUP BY Age, Name
will group by both age and name and will produce:
Age | Name | count |
---|---|---|
18 | luke | 3 |
21 | luke | 2 |
18 | matt | 1 |
21 | matt | 2 |