oracle 按小时统计表中各小时的数据量条数

2025-04-22 18:12:56

1、以下,例如,统计2016年5月06号一天各个小时内的数据量有多少,表名:TASK_RESULT, 统计按照stat_date字段的时间统计

2、select s.stat_date, 衡痕贤伎s.data_num from (select to_char(stat_date, '烤恤鹇灭yyyy/mm/dd hh24') || '点' as stat_date, count(1) as data_num from TASK_RESULT t where t.stat_date >= to_date('20160506', 'yyyymmdd') and t.stat_date < to_date('20160507', 'yyyymmdd') group by to_char(stat_date, 'yyyy/mm/dd hh24') || '点') s

3、注意,时间格式要用yyyy.mm.dd hh24,不要用hh,那样早上九点和晚上九点的就统计到一起了,因为hh是12小时制,统计结果,如下图:

oracle 按小时统计表中各小时的数据量条数

4、按15分钟统计,如下SQL:select count(*), (case floor((to_char(stat_date, 'mi')) / 15像粜杵泳) when 0 then to_char(stat_date, 'yyyy.mm.dd hh24') || ':00:00' when 1 then to_char(stat_date, 'yyyy.mm.dd hh24') || ':15:00' when 2 then to_char(stat_date, 'yyyy.mm.dd hh24') || ':30:00' when 3 then to_char(stat_date, 'yyyy.mm.dd hh24') || ':45:00' end) as stat_date from TASK_RESULT s where s.stat_date >= to_date('20160506', 'yyyymmdd') and s.stat_date < to_date('20160507', 'yyyymmdd')group by stat_date

5、统计结果,如下图:

oracle 按小时统计表中各小时的数据量条数
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢