Question : Multiple COUNT functions using one SELECT

Does anyone know how to get two COUNT functions working on one SELECT statement?  I need to be able to count the total number of items a location has and the total times those items have been used in one query so I can chart the results through SSRS using a bar chart.  The chart can only accept one dataset, so the counts have to exist in the same query.

I've tried putting counts on selects using inner joins, and as subqueries of the initial select statement but haven't had any luck yet.

Thanks!!

Answer : Multiple COUNT functions using one SELECT

if you're in SQL 2008, you can take advantage of the OVER clause. Check the query I've posted below (please note that I'm assuming your column names)

More info on the OVER clause here:

http://msdn.microsoft.com/en-us/library/ms189461.aspx

1:
2:
3:
4:
select 	distinct item
	count(item) over (partition by locationcolumn) countlocation,
	count(item) over (partition by usedcolumn) countused
from yourtable
Random Solutions  
 
programming4us programming4us