MySQL query from subquery not working

Posted by James Goodwin on Stack Overflow See other posts from Stack Overflow or by James Goodwin
Published on 2010-03-25T12:50:01Z Indexed on 2010/03/25 12:53 UTC
Read the original article Hit count: 493

Filed under:
|

I am trying to return a number based on the count of results from a table and to avoid having to count the results twice in the IF statement I am using a subquery. However I get a syntax error when trying to run the query, the subquery I have tested by itself runs fine.

Any ideas what is wrong with the query? The syntax looks correct to me

SELECT IF(daily_count>8000,0,IF(daily_count>6000,1,2))
FROM (
    SELECT count(*) as daily_count
    FROM orders201003
    WHERE DATE_FORMAT(date_sub(curdate(), INTERVAL 1 DAY),"%d-%m-%y") =
    DATE_FORMAT(reqDate,"%d-%m-%y")
) q

© Stack Overflow or respective owner

Related posts about mysql-query

Related posts about mysql