我有一张订单表、表中有个订单时间字段:etr_date,我想查询一天24小时、每个小时有几个订单,应该怎么写查询sql呢?
我想要的效果是:
00 01 02 03...23
1   2  3 5 ...10
请高手帮帮忙吧!谢谢了

解决方案 »

  1.   


    select sum(case when to_char(etr_date, 'hh24') = '00' then count(*) else 0 end) as "00",
           sum(case when to_char(etr_date, 'hh24') = '01' then count(*) else 0 end) as "01",
           ... ...
           sum(case when to_char(etr_date, 'hh24') = '22' then count(*) else 0 end) as "22",
           sum(case when to_char(etr_date, 'hh24') = '23' then count(*) else 0 end) as "23"
      from table
     group by etr_date
      

  2.   

    select to_char(etr_date,'hh') from Table where to_char(etr_date,'dd')='2011-09-05' group by to_char(etr_date,'hh')
      

  3.   

    学习,看楼上写的都很好啊,比我的严谨多了
    学习ing ~~~~