select case when time<30 then '小于30' 
when time>=30 and time<45 then '30到45'
when time>=45 and time<60 then '45到60'
when time>=60 and time<120 then '60到120'
else '120以上' end,count(*) from 表 group by case 
when time<30 then '小于30' 
when time>=30 and time<45 then '30到45'
when time>=45 and time<60 then '45到60'
when time>=60 and time<120 then '60到120'
else '120以上' end

解决方案 »

  1.   

    select case when time<30 then '小于30' when time>=30 and time<45 then '30到45' when time>=45 and time<60 then '45到60' when time>=60 and time<120 then '60到120'
    else '120以上' end,count(*) from 表 group by case when time<30 then '小于30' when time>=30 and time<45 then '30到45' when time>=45 and time<60 then '45到60' when time>=60 and time<120 then '60到120' else '120以上' end;
      

  2.   

    select count(*) from table group by decode(sign(time-30),0,'1',decode(sign(time-45),0,'2',decode(...)))
      

  3.   

    select 
    count(decode(time>30,0,1),
    count(decode(time>30,decode(time>45,0,1),0),
    count(decode(time>60,decode(time>120,0,1),0),
    count(decode(time>120,1,0)
    from 
    table
      

  4.   

    njypch(七世倾情):
    decode不是这么用的啊。不能用time>30的。select sum(decode(sign(time-30),-1,1,0)) as '30秒以内',
       sum(decode(sign(time-30),-1,0,decode(sign(time-45),-1,1,0))) as '30-45秒',
    .
    .
    .
       sum(decode(sign(time-120),1,1,0)) as '120秒以上'
    from table;
      

  5.   

    多谢各位,对有十几万条记录的表进行查询,
    以上语句中的速度最快是bzszp(SongZip) (大约3s),
    pengdali(大力 V3.0) 稍慢一点(3-4s),
    snowy_howe(天下有雪)最慢(超过5s)。但是在Delphi中执行都存在同样的问题:
    “多步操作产生错误.请检查每一步的状态值.”
    请问该如何解决?附:我的Delphi代码:
    ado_DS: TADODataSet;
    ado_DS := TADODataSet.Create(nil);
    ado_DS.Connection := ado_Connection;
    ado_DS.CommandText := sSQL;
    ado_DS.Open;
      

  6.   

    select count(decode(time>30,0,1),count(decode(time>30,decode(time>45,0,1),0),
    count(decode(time>60,decode(time>120,0,1),0),count(decode(time>120,1,0)from 
    table
      

  7.   

    to>>bzszp(SongZip) 
    你的语句我看不懂,向你学习....
      

  8.   

    select count(1) from table group by decode(round(time/10-3),0,'0',1,'1',2,'2',3,'3',4,'3',5,'3',6,'3',7,'3',8,'3',9,'3','4');