I have the following query
Select count(*) as TotalCount from ABC where ID in (1,3,6)
The problem here is that it gives me the total count of 1,3 and 6. But I would like to get the count for each ID, something like shown below:
TotalCount, ID
6, 1
2, 3
5, 6
Kindly let me know the SQL Server query for achieving this. I wouldn't prefer to use Temp tables.
simply add the id to the selected columns and group by them:
Select id, count(*) as TotalCount from ABC where ID in (1,3,6)
group by id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With