我需要我的过滤器仅返回当前日期的最后4天。我的斗争是正确使用DATEADD()和NOW()函数,因为我一直在不断收到错误。有什么建议吗?
截至目前,这是我的SQL声明:
SELECT COUNT(*) AS COUNT, DATE(CREATED_AT) AS CREATED_AT
FROM ACCOUNT
GROUP BY DATE(CREATED_AT)
ORDER BY CREATED_AT ASC
输出是这样的:
"result": [
{
"count": "1",
"created_at": "2016-11-12T06:00:00.000Z"
},
{
"count": "2",
"created_at": "2016-11-13T06:00:00.000Z"
},
{
"count": "1",
"created_at": "2016-11-14T06:00:00.000Z"
},
{
"count": "2",
"created_at": "2016-11-15T06:00:00.000Z"
}
],
编辑:我正在使用POSTGRES,我认为这会改变我可以用来识别日期的功能。
答案 0 :(得分:0)
您只需要一个简单的dprintf
子句。假设你没有未来日期:
WHERE
答案 1 :(得分:0)
经过一些研究后,我发现了一个有效的POSTGRES友好版本!
SELECT COUNT(*) AS COUNT,
DATE(CREATED_AT) AS CREATED_AT
FROM ACCOUNT WHERE CREATED_AT >= NOW() - INTERVAL '4 DAYS'
GROUP BY DATE(CREATED_AT)
ORDER BY CREATED_AT ASC