Home >Database >Mysql Tutorial >How to query the data of the last 7 days in mysql

How to query the data of the last 7 days in mysql

王林
王林Original
2020-10-15 11:35:4314095browse

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.

How to query the data of the last 7 days in mysql

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn