mysql 30天_Mysql-最近30天

bd96500e110b49cbb3cd949968f18be7.png

I have a Table with two colums.

The first column is a date stored as: (example): 01/01/2015 00:00:00

The seconds column is a number : as (example) : 500

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

I want only the data for the last month as a result of the query (last 30 days).

Would appreciate any help..

Edit as per OP comments:

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?

解决方案

Edit: Changed query as per OP

select *

from cc_open_incident_view

WHERE date between (CURDATE() - INTERVAL 1 MONTH ) and CURDATE()

Previous Answer:

If date is saved as date then use this

select *

from cc_open_incident_view

WHERE date >= (CURDATE() - INTERVAL 1 MONTH )

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 )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值