第1个回答 2010-10-25
select 费用区间=(case when 费用>=10 and 费用<20 then '10-20' when 费用>=20 and 费用<30 then '20-30' end),count(*) as 个数, sum(费用) as 费用总计
from 表
group by (case when 费用>=10 and 费用<20 then '10-20' when 费用>=20 and 费用<30 then '20-30' end)
类似,如果要多个分类,可在case里多加几个 when本回答被网友采纳
第2个回答 2010-10-25
select 号码,
sum(case when 费用 between 10 and 20 then 费用 else 0 end)[10-20],
sum(case when 费用 between 21 and 30 then 费用 else 0 end)[21-30],
sum(case when 费用 between 31 and 40 then 费用 else 0 end)[31-40],
sum(case when 费用 between 41 and 50 then 费用 else 0 end)[41-50],
sum(case when 费用 between 51 and 60 then 费用 else 0 end)[51-60],
sum(case when 费用 between 61 and 70 then 费用 else 0 end)[61-70],
sum(case when 费用 between 71 and 80 then 费用 else 0 end)[71-80]
.....
from 表
group by 号码
第3个回答 2010-10-25
select 费用/10,sum(费用),count(1) from 表 group by 费用/10本回答被提问者采纳
第4个回答 2010-10-25
declare @t table (hm varchar(10),fy int)
insert @t values ('23456',12)
insert @t values ('56423',13)
insert @t values ('56321',15)
insert @t values ('89546',25)
insert @t values ('78965',85)
insert @t values ('56789',88)
select bj,count(fy) as sl,sum(fy) as hj from (
select *,substring(cast(fy as varchar(10)),1,1) as bj
from @t) a
group by bj