34,594
社区成员
发帖
与我相关
我的任务
分享
select sum(case when 分数<60 then 1 else 0 end )[<60],
sum(case when 分数 between 60 and 69 then 1 else 0 end )[60~69],
sum(case when 分数 between 70 and 79 then 1 else 0 end )[70~79],
sum(case when 分数 between 80 and 89 then 1 else 0 end )[80~89],
sum(case when 分数 between 90 and 99 then 1 else 0 end )[90~99],
sum(case when 分数=100 then 1 else 0 end )[100]
from tb
SELECT 分数段,
SUM(CASE WHEN 分数<60 THEN 1 ELSE 0)AS 人数..
SUM(CASE WHEN 分数<60 THEN 1 ELSE 0)AS 人数..
SUM(CASE WHEN 分数<60 THEN 1 ELSE 0)AS 人数..
FROM TB
select * from
(
select 分数段 = '<60' , count(1) as 人数 from tb
union all
select 分数段 = '60~69' , count(1) as 人数 from tb
union all
select 分数段 = '70~79' , count(1) as 人数 from tb
union all
select 分数段 = '90~99' , count(1) as 人数 from tb
union all
select 分数段 = '100' , count(1) as 人数 from tb
) t
order by case when 分数<60 then 1
case when 分数 between 60 and 69 then 2
case when 分数 between 70 and 79 then 3
case when 分数 between 80 and 89 then 4
case when 分数 between 90 and 99 then 5
case when 分数=100 then 6 end
select * from
(
select 分数段 = '<60' , 分数 = 语文,人数 from tb
union all
select 分数段 = '60~69' , 分数 = 数学,人数 from tb
union all
select 分数段 = '70~79' , 分数 = 物理,人数 from tb
union all
select 分数段 = '90~99' , 分数 = 数学,人数 from tb
union all
select 分数段 = '100' , 分数 = 物理,人数 from tb
) t
order by case when 分数<60 then 1
case when 分数 between 60 and 69 then 2
case when 分数 between 70 and 79 then 3
case when 分数 between 80 and 89 then 4
case when 分数 between 90 and 99 then 5
case when 分数=100 then 6 end
select * from
(
select 分数段='[100]',count(*) as 个数 from tb where 分数=100
union all
select 分数段='[90~99]',count(*) as 个数 from tb where 分数 between 90 and 99
union all
select 分数段='[80~89]',count(*) as 个数 from tb where 分数 between 80 and 89
union all
select 分数段='[70~79]',count(*) as 个数 from tb where 分数 between 70 and 79
union all
select 分数段='[60~69]',count(*) as 个数 from tb where 分数 between 60 and 69
union all
select 分数段='[<60]',count(*) as 个数 from tb where 分数<60
)
select 分数段='[100]',count(*) as 个数 from tb where 分数=100
union all
select 分数段='[90~99]',count(*) as 个数 from tb where 分数 between 90 and 99
union all
select 分数段='[80~89]',count(*) as 个数 from tb where 分数 between 80 and 89
union all
select 分数段='[70~79]',count(*) as 个数 from tb where 分数 between 70 and 79
union all
select 分数段='[60~69]',count(*) as 个数 from tb where 分数 between 60 and 69
union all
select 分数段='[<60]',count(*) as 个数 from tb where 分数<60
[code=SQL]
select 分数段='[100]',count(*) as 个数 from tb where 分数=100
union all
select 分数段='[90~99]',count(*) as 个数 from tb where 分数 between 90 and 99
union all
select 分数段='[80~89]',count(*) as 个数 from tb where 分数 between 80 and 89
union all
select 分数段='[70~79]',count(*) as 个数 from tb where 分数 between 70 and 79
union all
select 分数段='[60~69]',count(*) as 个数 from tb where 分数 between 60 and 69
union all
select 分数段='[<60]',count(*) as 个数 from tb where 分数<60
[/code]