Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Count * where Count * meets a certain criteria

Author  Topic 

CoffeeAddict
Yak Posting Veteran

94 Posts

Posted - 2010-05-18 : 17:54:36
God I hate SQL (sorry I'm just frustrated..but really do hate it).

select COUNT(*)
from Order nolock
where payType = 'PayPal'
and COUNT(*) < 600
and completedOn < '5/18/2010'

I can't get this to work. Give me how many days where I had a total < 600 orders for each day.

I tried to use a nested select such as select blah blah > 1 and I have no clue how to make SQL "Happy" in this case.

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-05-18 : 18:29:29
Maybe this?
SELECT 
CompletedOn,
COUNT(*) AS DailyCount
FROM
[Order]
WHERE
CompletedOn < '20100518'
AND PayType = 'PayPal'
GROUP BY
CompletedOn
HAVING
COUNT(*) < 600
This might help:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -