Mysql method to query the data of the last 7 days: directly execute the [SELECT * FROM table name WHERE date_sub(curdate(), interval 7 day) <= date (time field);] statement.
The SQL statement is as follows:
(Recommended tutorial: mysql video tutorial)
Query today’s data
SELECT * FROM 表名 WHERE to_days(时间字段) = to_days(now());
Query yesterday’s data
SELECT * FROM 表名 WHERE to_days(now()) - to_days(时间字段) <= 1;
Query the last seven days’ data
SELECT * FROM 表名 WHERE date_sub(curdate(), interval 7 day) <= date(时间字段);
Related recommendations: mysql tutorial
The above is the detailed content of How to query the data of the last 7 days in mysql. For more information, please follow other related articles on the PHP Chinese website!