oracle 按小时分组 只是一天的记录

select b.dt,nvl(a.ct,0)
  from (select trunc(logtime, 'hh24') dt, count(0) ct
          from svisitor
         group by trunc(logtime, 'hh24')) a,
       (select trunc(sysdate, 'dd') + (level-1) / 24 dt
          from dual
        connect by level < 25) b
where a.dt(+)=b.dt
order by b.dt

你可能感兴趣的:(oracle)