ITPub博客

首页 > IT职业 > IT图书 > oracle中的“复杂”分组统计sql

oracle中的“复杂”分组统计sql

IT图书 作者:cartoonfish 时间:2021-09-09 09:11:12 0 删除 编辑

要求:

呼叫系统(Call Center)每天会有大量的电话进线数据,领导们要查看每天的进线数汇总,并且要求把 每天从上午8点到上午12点以及下午2点到晚上8点这两个时间段的数据汇总 “视”为当天的数据。--即分组依据
 

思路:把时间段折分成连续二段,一段是从当天08:00到11:59分的数据,一段是当日12:01到19:59分的数据,然后用union all合并起来,最后再用sum求和


select sum(总数) 总数,时间 from (
  select 
    count(ID) 总数, 
    to_char(CallDateTime,'yyyy-mm-dd') 时间 
  from 
    T_Test t 
  where to_char(CallDateTime,'hh24')>='08' and to_char(CallDateTime,'hh24')='12' and to_char(CallDateTime,'hh24')

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1409/viewspace-2800139/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Docsify 深入源码
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    96
  • 访问量
    515