Monday 3 September 2018

The Mysql query does not work with WHERE

I was trying to get some data from my database, however I am currently only getting errors.

The query I am trying to do =
SELECT
   count(id),
   day(created_at),
   year(created_at),
   month(created_at)
FROM
   `orders`
WHERE
   day(created_at) = BETWEEN 1 AND 7 month(created_at) = 6
   AND year(created_at) = 2014
   AND company_id = 1
group by
   year(created_at),
   month(created_at),
   day(created_at)

The days between 1 and 7 will be the days sunday trough saturday to get all orders in that week.
Thanks in advance.

   You have SQL Syntax errors , MISSING "AND" and "BETWEEN" not used correctly.
   Try the following:-

    SELECT COUNT(id), day(created_at), year(created_at), month(created_at)
    FROM
   `orders`
    WHERE day(created_at)  BETWEEN 1 AND 7
    AND  month(created_at) = 6
    AND year(created_at) = 2014
    AND company_id = 1
    GROUP BY year(created_at), month(created_at), day(created_at);

0 comments:

Post a Comment