有一堆数据。我想写个SQL语句,查出的结果是0-4点的,4-8点的,8-12点的一次类推。select time,count(*) from table group by time order by time类似的哦
最终查出的结果是:0-4   5
4-8   8  等等      
后面的是我虚拟的count。不一定是time  但肯定是数字。select time,count(*) from table group by time order by time
单纯按照这种查他仅仅显示是同一时间的数量。所以 想弄时间段里的,希望知道的告诉我。谢谢哦

解决方案 »

  1.   

    这个要求和分析函数没什么关系
    试试这样写
    select trunc(time)+trunc((time-trunc(time))*6)/6,count(1)
    from table1
    group by trunc(time)+trunc((time-trunc(time))*6)/6
    order by 1
      

  2.   

    select time , count(1) from

      select 
      case when time >= 0 and time < 4 then '0-4'
           when time >= 4 and time < 8 then '4-8'
           when time >= 8 and time < 12 then '8-12'
      end time from table
    ) t
    group by time
      

  3.   

    select 
      trunc(d1), round(to_number(to_char(d1,'HH24'))/4),count(*)
    from 
    (
    select sysdate d1 from dual
    ) a
    group by trunc(d1), round(to_number(to_char(d1,'HH24'))/4)
      

  4.   

    如果你的TIME是时间字段,不能这么用.
    最好给出完整的表结构,测试数据,计算方法和正确结果.发帖注意事项
    http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
      

  5.   

    是number类型哈。不是时间字段哦
      

  6.   

    1楼和3楼,是针对date型处理
    2楼是number型
    用number来表示时间?好奇怪的做法