我想获得最后24小时的数据.我在postgresql中写了一个查询,如下所示.但我无法按照我的预期得到答案.
SELECT startdate::timestamp AS startdate,(DATE_PART('hour',startdate::timestamp)::integer) as hrs,count(guorderid) FROM ord_entitlement WHERE DATE_PART('Day',CURRENT_DATE::timestamp - startdate::timestamp) < 1 AND DATE_PART('hour',startdate::timestamp) <= 24 GROUP BY hrs,startdate ORDER BY startdate
如果您使用CURRENT_DATE,则不会使用now()函数.试试以下,
原文链接:https://www.f2er.com/postgresql/238874.htmlSELECT startdate::timestamp AS startdate,count(guorderid) FROM ord_entitlement WHERE DATE_PART('Day',now() - startdate::timestamptz) < 1 GROUP BY hrs,startdate ORDER BY startdate