某张表中存在用户字段 user_id,及对应金额字段 user_Fee 其数值为 
user_id          user_Fee
001               85.37
002               108.43
003               364.25
001               207.56
...                 ...现在想查询出所有100元分段为分组的用户数,如:
0-100元: 30个用户
100-200元: 20个用户
.....请问怎样实现,谢谢

解决方案 »

  1.   

    select trunc(sum_user_fee/100), count(1) from 
    (
    select user_id, sum(user_Fee) as sum_user_fee from table_name
    group by user_id
    )
    group by trunc(sum_user_fee/100)
      

  2.   

    select case when user_Fee>0 and user_Fee<100 then 0-100元
                when user_Fee>=101 and user_Fee<200 then 100-200元
                ...
                .....
           end as fenduan,
           count(user_id)
    from table
    group by 
    case when user_Fee>0 and user_Fee<100 then 0-100元
                when user_Fee>=101 and user_Fee<200 then 100-200元
                ...
                .....
           end as fenduan
      

  3.   

    xiaoxiao1984(笨猫儿):高,向您学习