表结构:
id  mobile  price
1   123456    1.00
2   123456    1.00
3    4566     1.00
4    789      1.00
5    753      1.00
6   123456    1.00
7    789      1.00
我想查出的结果是
消费1块的有几个用户
消费2快的有几个用户
依次类推
如:
消费钱数  用户
1   2
2   1
3   3谢谢了

解决方案 »

  1.   


    create table #tb
    (id int identity(1,1), mobile nvarchar(20), price float)
    insert #tb
    select '123456', 1.00 union all
    select '123456',1.00 union all
    select '4566',1.00 union all
    select '789',1.00 union all
    select '753',1.00 union all
    select '123456',1.00 union all
    select '789',1.00
    select price as 消费钱数 ,count(1) 用户数 from #tb group by price这样?
      

  2.   

    如果mobile是客户标示的话select xf,count(*) from 
    (select mobile, sum(price) xf from test111 group by mobile) as b group by b.xf
      

  3.   

    select p as 消费钱数,count(1) as 用户
    (
    select mobile,sum(price) as p from tb group by mobile
    ) t
    group by p
      

  4.   


    declare @table table (id int,mobile int,price numeric(3,2))
    insert into @table
    select 1,123456,1.00 union all
    select 2,123456,1.00 union all
    select 3,4566,1.00 union all
    select 4,789,1.00 union all
    select 5,753,1.00 union all
    select 6,123456,1.00 union all
    select 7,789,1.00select price,count(*) as mycount from (
    select mobile,sum(price) as price from @table group by mobile
    ) a group by price
    /*
    price                                   mycount
    --------------------------------------- -----------
    1.00                                    2
    2.00                                    1
    3.00                                    1
    */