select count(*) from people where height <= 190 group by (height/10)
union all
select count(*) from people where height > 190 ;

解决方案 »

  1.   

    select count(*) from people where height <= 190 group by floor(height/10)
    union all
    select count(*) from people where height > 190 ;
      

  2.   

    select count(*),'h<150' from people where height <=150
    union 
    select count(*),'151-160' from people where height between 151 and 160 
    union 
    select count(*),'161-170'  from people where height between 161 and 170 
    union 
    select count(*),'171-180'  from people where height between 171 and 180 
    union 
    select count(*),'181-190'  from people where height between 181 and 190 
    union 
    select count(*),'h>=191' from people where height >=191
      

  3.   

    select count(*) from people where height <= 190 group by floor(height/10)
    union all
    select count(*) from people where height > 190 ;
      

  4.   

    楼上各位:
    本人是oracle门外汉!请推荐一本入门书,(本人原来做SQL server,算熟)
      

  5.   

    select 
    (select count(*) where height<150) as col1,
    (select count(*) where height>=150 and height<160) as col2,
     ....
    from dual;
      

  6.   

    楼上各位:
    本人是oracle门外汉!请推荐一本入门书,(本人原来做SQL server,算熟)
      

  7.   

    select a.range, count(*) from 
    ( select decode(sign(height - 150),-1,'150cm以下',sign(height - 160),-1,'150-160',sign(height - 170),-1,'160-170',sign(height - 180),-1,'170-180',sign(height - 190),-1,'180-190','190以上') range from people) a
    group by a.range
      

  8.   

    select sum(decode(sign(height - 150),-1,1,0)) 150cm以下,
           sum(decode(sign(160-height)*sign(height-150),1,1,0)) 150-160,
           sum(decode(sign(170-height)*sign(height-160),1,1,0)) 150-160,
           sum(decode(sign(180-height)*sign(height-170),1,1,0)) 150-160,
           sum(decode(sign(190-height)*sign(height-180),1,1,0)) 150-160,
           sum(decode(sign(190-height,1,1,0)) 190以上
    from table_name;
      

  9.   

    select (select count(*) from people where height between 150 and 160) h150_160,
    (select count(*) from people where height between 161 and 170) h160_170,
    (select count(*) from people where height between 171 and 180) h170_180,
    (select count(*) from people where height between 181 and 190) h180_190,
    (select count(*) from people where height>190) h1190_over from people where rownum<=1;
      

  10.   

    使用首先缩小数值,然后四舍五入取整方法,然后使用group by 不就可以了吗
      

  11.   

    select count(*),round((height/100)) from people
    group by round((height/100))
      

  12.   

    回复人: Lastdrop(空杯) ( ) 信誉:115  2003-05-12 17:30:00  得分:0 
     
     
      select a.range, count(*) from 
    ( select decode(sign(height - 150),-1,'150cm以下',sign(height - 160),-1,'150-160',sign(height - 170),-1,'160-170',sign(height - 180),-1,'170-180',sign(height - 190),-1,'180-190','190以上') range from people) a
    group by a.range
      
     
    这里的decode是pl/sql里的还是T_sql里的?他的参数分别代表什么意思?
      

  13.   

    SQL> select trunc(height,-1) || '-' || trunc(height+10,-1) as 身高,count(*) as 人数
      2  from people
      3  group by trunc(height,-1) || '-' || trunc(height+10,-1);身高
    --------------------------------------------------------------------------------
          人数
    ----------
    140-150
             1170-180
             2
      

  14.   

    to: tqinghaijn(海) decode是pl/sql的函数decode(a,b,c,d,e...,z)相当于 if a = b then
              return c;
           elsif a=d then
              return e;
           ...
           else
              return z;
           end if;
      

  15.   

    非迫不得已
    请不要选择decode, case when 之类的处理方法
    效率很低,严重占用服务器的内存空间
    而且在表达上过分抽象!可读性差,不利于维护
      

  16.   

    to:greatplain, 真的是这样吗
      

  17.   

    to: Lastdrop(空杯) 
    多谢!!!
      

  18.   

    我用临时表来处理的,就是一张表专用来放段值的,OK了对,DECODE之类,效率很低,数据亮不大,并发不多的情况下可以使用。