环境
postgresql-14
按小时统计业务
SELECT
count(1),
to_char(gmt_create, 'YYYY-MM-DD HH24' ) AS d
FROM
table_name
WHERE
gmt_create >'2023-12-13 11:30:00'
GROUP BY d
ORDER BY d
按天统计
SELECT
count(1),
to_char(gmt_create, 'yyyy-MM-dd' ) AS d
FROM
table_name
WHERE
gmt_create BETWEEN '2022-11-01' and '2022-11-12'
GROUP BY d
ORDER BY d
按分钟统计
SELECT
count(1),
to_char(gmt_create, 'HH24-mi' ) AS d
FROM
table_name
WHERE
gmt_create >'2023-12-13 11:30:00'
GROUP BY d
ORDER BY d
标签:11,GROUP,postgresql,create,char,table,小时,统计,gmt
From: https://blog.51cto.com/bomby/8806071