...'Category 3')
insert into #temp1 values ('def', 'Category 4')
insert into #temp1 values ('def', 'Category 3')
go
select id, category, count(*) from #temp1 group by id, category order by id, category
go
--- ---------------------------------------
The result set shows:
id category
abc...