我需要上个月记录的数据,而不是当前日期-1个月的数据。
这是我的错误查询:D
SELECT MIN(date(Timestamp)) as fDate , MAX(date(Timestamp)) as tDate FROM data WHERE boxid=45 AND
YEAR(Timestamp) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
AND MONTH(Timestamp) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
编辑:我的表格中有很多数据,我只想查看最后一次重新编码数据的开始位置和结束位置,但我想要上个月。
例如,表格已经记录到1月17日。
我现在想要2个日期:1月1日和17日
我试过这个
SELECT max(date(Timestamp)) as toDate, min(date(timestamp)) as fromDate FROM data WHERE timestamp<=(SELECT MAX(date(Timestamp)) FROM data )
AND timestamp>=(SELECT (MAX(date(Timestamp))- INTERVAL 1 MONTH) FROM data ) AND ID=10
它有一种奇怪的行为,它给我的不是30天......
答案 0 :(得分:1)
好吧,为了试试这个,我创建了一个名为&#39;录音&#39;它只包含id
(int)和timestamp
(时间戳)。
这里是表格的内容:
SELECT * FROM `recordings` WHERE `timestamp` <= ( SELECT `timestamp` FROM `recordings` ORDER BY `timestamp` DESC LIMIT 1 ) AND `timestamp` >= (( SELECT `timestamp` FROM `recordings` ORDER BY `timestamp` DESC LIMIT 1 ) - INTERVAL 1 MONTH))
答案 1 :(得分:0)
最后一个月可用数据的第一天由:
给出MAX(DATE(`Timestamp`)) - INTERVAL (DAYOFMONTH(`Timestamp`) - 1 ) DAY
-- e.g., 2016-09-16 - INTERVAL (16 - 1) DAY => 2016-09-01
,最新的可用日期只是
MAX(DATE(`Timestamp`))
所以你可以
SELECT last_day - INTERVAL (DAYOFMONTH(last_day) - 1) DAY AS first_day,
last_day
FROM (SELECT MAX(DATE(`Timestamp`)) AS last_day FROM data) derived;
(当然,你不需要那个派生表,但我发现它比重复 max(日期(`blah`))更具可读性。)
答案 2 :(得分:-1)
int MapRenderingInterfacer::CurrentCacheSize::get()
{
return (*_nativeMapRenderingInterface)->getCurrentCacheSize()/1000000;
}