Bear with me, I suck at doing subqueiries and need a bit of help.
I want to do:
Select SUM(mycount),item_id FROM mytable WHERE SUM(mycount)>10 AND DATEDIFF(day,datestamp,GETDATE())<=30 GROUP BY item_id
This of course fails with an error like the follow:
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
What's the optimal way do to this?
I want to do:
Select SUM(mycount),item_id FROM mytable WHERE SUM(mycount)>10 AND DATEDIFF(day,datestamp,GETDATE())<=30 GROUP BY item_id
This of course fails with an error like the follow:
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
What's the optimal way do to this?