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

王林
Release: 2020-10-15 11:35:43
Original
14032 people have browsed it

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());
Copy after login

Query yesterday’s data

SELECT * FROM 表名 WHERE to_days(now()) - to_days(时间字段) <= 1;
Copy after login

Query the last seven days’ data

SELECT * FROM 表名 WHERE date_sub(curdate(), interval 7 day) <= date(时间字段);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template