PGsql实现每一天按小时分组

sql SELECT sum(type) lineysum,to_char(createtime,'yyyy-MM-dd HH24') linextime,8 as type FROM ad_log WHERE to_char(createtime, 'yyyy-MM-dd') =to_char(now()::timestamp + '-3 day', 'yyyy-MM-dd') GROUP BY to_char(createtime,'yyyy-MM-dd HH24') ORDER BY linextime;

结果

如何生成完整24小时,没有则为0?

回答

	 SELECT  timeconfig.time  

FROM

( SELECT to_char(generate_series(to_date('20200724','yyyyMMdd'), to_date('20200725','yyyyMMdd'), '1 hours') ,'yyyy-MM-dd HH24') AS time) AS timeconfig

这段sql实现这个功能

以上是 PGsql实现每一天按小时分组 的全部内容, 来源链接: utcz.com/a/34786.html

回到顶部