oracle中同N天前每小时数据对比,数据列在同一行

select to_char(a.create_time, ‘hh24’) 小时,
sum(case when to_char(a.create_time, ‘yyyymmdd’) =to_char(sysdate,‘yyyymmdd’) then data end ) 当前天每小时数据求和,
sum(case when to_char(a.create_time, ‘yyyymmdd’) =to_char(sysdate-7,‘yyyymmdd’) then data end ) 七天前每小时数据求和
from table a group by to_char(a.create_time, ‘hh24’) order by 1;

发布了8 篇原创文章 · 获赞 3 · 访问量 108

猜你喜欢

转载自blog.csdn.net/weixin_39096855/article/details/105700467
今日推荐