[Oracle]以5分钟为单位,统计每个单位内记录数

select count(tmp.TRAVELTIME) totalNum,tmp.newTime
from(
  select t.TRAVELTIME, -- 任意标识
         to_char(t.UPTIME,'yyyymmddhh24mi') oldTime, -- 原来的时间
         case when substr(to_char(t.UPTIME,'mi'),2,1)<5 
         then
             to_char(t.UPTIME,'yyyymmddhh24')||substr(to_char(t.UPTIME,'mi'),1,1)||0
         else 
             to_char(t.UPTIME,'yyyymmddhh24')||substr(to_char(t.UPTIME,'mi'),1,1)||5 
         end as newTime  -- 字符串拼接出时间段伪列     
  from "tengxun_speed" t
  where t.UPTIME>=to_date('20160406000000','yyyymmddhh24miss')
  order by t.UPTIME asc
) tmp
group by tmp.newTime
order by totalNum desc

你可能感兴趣的:([Oracle]以5分钟为单位,统计每个单位内记录数)