Slightly confused as I got a notification email saying:
Assume you edited that afterwards....
Originally Posted by
tiredhero16
My mistake for not being very clear. What I intended to say was that I am trying to sort by how many items per category are not in stock (0). I think that is easier than the SQL code you provided, but I still can't figure it out.
I think you mean COUNT items WHERE not in stock i.e. Units in Stock = 0
Code:
SELECT Count(TableName.[Product Category]) AS [Total Products]
FROM TableName
WHERE TableName.[Units in Stock] = 0;
For the data shown, this gives Total Products = 8
If you want GROUPING as well
Code:
SELECT TableName.[Product Category], Count(TableName.[Product Category]) AS [Total Products]
FROM TableName
WHERE TableName.[Units in Stock] = 0
GROUP BY TableName.[Product Category]
ORDER BY TableName.[Product Category];
This gives Birdhouses = 3 ; Planters = 1 ; Windchimes = 4