Mysql:过去七天的结果 [英] Mysql: results from last seven days
本文介绍了Mysql:过去七天的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我第一次用PHP和MySQL创建一个网站。如何查询Mysql搜索的结果以仅显示过去7天的结果?
It's my first time creating a website with PHP and MySQL. How do I query the results of a Mysql search to display only the results from the last 7 days?
我的数据库中的列是:
Id
Name
Date
Mensage
推荐答案
有几种方法可以做到这一点。这是一个。
There's a few ways to do this. Here's one.
SELECT *
FROM tablename
WHERE `date` > CURRENT_DATE - INTERVAL 7 DAY
另一个:
SELECT *
FROM tablename
WHERE DATEDIFF(`date`, CURRENT_DATE) < 7
FYI,您不应该使用保留关键字。这是一个坏主意,只会对你造成问题。
FYI, you should not name your columns using reserved keywords. It's a bad idea and can only cause problems for you.
这篇关于Mysql:过去七天的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文