如何在postgreSQL中获取最后24小时的数据

前端之家收集整理的这篇文章主要介绍了如何在postgreSQL中获取最后24小时的数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想获得最后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()函数.试试以下,
SELECT startdate::timestamp AS startdate,count(guorderid)
        FROM ord_entitlement
        WHERE DATE_PART('Day',now() - startdate::timestamptz) < 1
        GROUP BY  hrs,startdate
        ORDER BY startdate
原文链接:https://www.f2er.com/postgresql/238874.html

猜你在找的Postgre SQL相关文章