this error would've been a lot easier to spot if you had been using the leading comma convention, along with suitable formatting...
Code:
SELECT ProgramName AS `name`
, SUM(CASE WHEN Billable = 'PENDING' THEN 1 ELSE 0 END) AS `pending_leads`
, SUM(CASE WHEN Billable = 'PASS' THEN 1 ELSE 0 END) AS `pass_leads`
, SUM(CASE WHEN Billable = 'FAIL' THEN 1 ELSE 0 END) AS `fail_leads`
, -- a lot easier to see this, eh?
FROM leads
WHERE ProgramID = '1'
AND `TimeStamp` >= '2013-01-01 00:00:00'
AND `TimeStamp` < '2013-01-31 23:59:99'
GROUP
BY ProgramName
do a search (on "leading comma") in this forum for other examples of people who have had exactly the same problem
FYI, you're on the right track with your datetime range tests, but you're (incorrectly) omitting a small portion of the 31st
do it this way instead --
Code:
AND `TimeStamp` >= '2013-01-01'
AND `TimeStamp` < '2013-02-01'
this technique works correctly for both DATE and DATETIME columns, with the added bonus that you never have to figure out leap years
Bookmarks