简体   繁体   中英

How to decrease SQL Query from last 30 days until now?

I am trying to get the amount of data for the last 30 days.

SELECT ( Now() - interval 1 month ), 
   Count(flightid) AS count 
FROM   flight 
WHERE  flightstatus = 0 
   AND flightvisibility = 1 
   AND flightvaliddate > Now() 
   AND flightvaliddate >= ( Now() - interval 1 month ) 

Right now this is working ok and it's giving me only 1 row that corresponds to the same day of last month.

What I would like is to get the remaining data from each day until now. How can I do this?

I am using MySQL.

The condition in the WHERE clause is wrong.

And since you want day wise data of last thirty days till now then you must have to use GROUP BY .

SELECT
    DATE(flightvalidate) AS flightValidateDate,
    Count(flightid) AS count
FROM
    flight
WHERE
    flightstatus = 0
    AND flightvisibility = 1
    AND DATE(flightvaliddate) >= CURDATE() - INTERVAL 1 MONTH 
GROUP BY flightValidateDate
ORDER BY flightvalidate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM