除了昨天我想要从上周返回日期,我想只返回昨天的数据。
我的last week
查询看起来像这样
SELECT b.id,
b.publisher_id,
b.name,
b.size,
b.present,
b.display,
d.book_id AS
download,
b.download_date
FROM books b LEFT
JOIN
downloads d ON
d.book_id=b.id
WHERE DATE(b.download_date) >= CURRENT_DATE - INTERVAL '1 week'
AND NOT DATE(b.download_date) > CURRENT_DATE - INTERVAL '1 day'
yesterday
数据的查询如下所示
SELECT b.id,
b.publisher_id,
b.name,
b.size,
b.present,
b.display,
d.book_id AS
download,
b.download_date
FROM books b LEFT
JOIN
downloads d ON
d.book_id=b.id
WHERE DATE(b.download_date) = CURRENT_DATE - INTERVAL '1 day'
但他们会返回相同的结果。为什么?
我的数据如下所示"2014-06-16 07:56:27.672+00"
是download_date
2655;85;"Amsco - Jeff Beck Anthology.rar";12893115;f;f;;"2014-06-16 07:56:27.672+00"
3035;108;"Apress - Big Data Analytics.rar";8254213;f;f;;"2014-06-16 07:56:27.672+00"
7076;291;"Century - Wall and Piece.rar";66864919;f;f;;"2014-06-16 07:56:27.672+00"
266;9;"A K Peters - Video-Based Rendering.rar";2096583;f;f;;"2014-06-16 07:56:27.672+00"
我当前的日期 - 2014-06-17 10:40 ....
问题是什么?
答案 0 :(得分:1)
根据您的数据,所有下载均来自昨天。 (当前:06-17,下载06-16)。昨天的查询工作正常,因为当前日期减去1天正好是下载日期。错误在于第一个查询:
AND NOT DATE(b.download_date) > CURRENT_DATE - INTERVAL '1 day'
必须更改为
AND NOT DATE(b.download_date) >= CURRENT_DATE - INTERVAL '1 day'
因为目前您只排除今天的下载量(下载日期大于昨天)