create table t1 (id int identity (1,1),price int)insert t1
select 23
union all select 24
union all select 28
union all select 31
union all select 38
union all select 45
union all select 58
union all select 59
select *,cc=left(price,1) into #t from t1 select count(*) as num,cc from #t group by cc大概是这样吧

解决方案 »

  1.   


    select 范围=case
    when 20<price and price<30 then '21-30'
    when 30<price and price<40 then '31-40'
    when 40<price and price<50 then '41-50'
    when 50<price and price<60 then '51-60'
    else '其他' end
    ,数量=count(*)
    ,百分比=cast(cast(sum(100.0)
    /(select count(*) from 表) as decimal(10,2)) as varchar)+'%'
    from 表
    group by case
    when 20<price and price<30 then '21-30'
    when 30<price and price<40 then '31-40'
    when 40<price and price<50 then '41-50'
    when 50<price and price<60 then '51-60'
    else '其他' end
      

  2.   

    百分比=cast(cast(sum(100.0)
    /(select count(*) from 表) as decimal(10,2)) as varchar)+'%'
    邹建 这句你能给我解释一下吗?我不知道这个是什么意思 
    谢谢你了