Getting the amount of each item

I have the following request

Select count(*) as TotalCount from ABC where ID in (1,3,6) 

The problem here is that it gives me a total of 1.3 and 6. But I would like to get a quantity for each identifier, as shown below:

 TotalCount, ID 6, 1 2, 3 5, 6 

Please let me know the SQL Server query to achieve this. I would not prefer to use temporary tables.

+1
source share
2 answers

just add the id to the selected columns and group them:

 Select id, count(*) as TotalCount from ABC where ID in (1,3,6) group by id 
+3
source
 select count(*),id from abc where id in (1,3,6) group by id; 
0
source

Source: https://habr.com/ru/post/1499311/


All Articles