Mysql-最近30天 [英] Mysql -- Last 30 days
问题描述
我有一张有两个柱子的桌子.
I have a Table with two colums.
- 第一列是存储为以下日期的日期:(示例):
01/01/2015 00:00:00
- 秒列是一个数字:(例如):500
我写了一个如下的SQL语句:
I have written an SQL Statement which looks like this:
select *
from cc_open_incident_view
WHERE (DATE =(NOW() - INTERVAL 1 MONTH))
如果执行此语句,它不会检索任何数据,而且我也找不到错误
If I execute this statement it doesn't retrieve any data and I can't find the mistake
由于查询(最近30天),我只需要最后一个月的数据.
I want only the data for the last month as a result of the query (last 30 days).
非常感谢您的帮助.
根据OP注释进行
日期保存为日期,并且可以使用,但是我表中的列日期已存储了未来5年的日期,并且它还显示如下数据:09.03.2016
(也就是明天).有什么方法只能显示从30 days
开始到today
的日期吗?
Date is saved as date and it's working, but the column date in my table has stored the dates for the next 5 years and it shows the data like: 09.03.2016
(which is tomorrow) too. Is there any way to only show the date from 30 days
back till today
?
推荐答案
根据OP更改了查询
select *
from cc_open_incident_view
WHERE date between (CURDATE() - INTERVAL 1 MONTH ) and CURDATE()
上一个答案:
如果日期另存为date
,请使用此
If date is saved as date
then use this
select *
from cc_open_incident_view
WHERE date >= (CURDATE() - INTERVAL 1 MONTH )
如果日期另存为字符串,则使用该日期(假设它在dd/mm/yyyy ...
If date is saved as string then use this (assuming it is in dd/mm/yyyy ...
select *
from cc_open_incident_view
WHERE STR_TO_DATE(date ,''%d/%m/%y %h:%i:%s')>= (CURDATE() - INTERVAL 1 MONTH )
这篇关于Mysql-最近30天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!