select '语文3',round(sum(iif(语文>=70.5,1,0))/count(*)*100,2) as 优秀率,round(sum(iif(语文>=58,1,0))/count(*)*100,2) as 良好率,round(sum(iif(语文>=48,1,0))/count(*)*100,2) as 及格率,round(avg(语文),2) as 平均分 from cj where 班级='26'
上面的语句在ACCESS中,可以运行。在SQLSERVER中,不能运行,应该怎么修改一下呢?
------解决方案--------------------
select '语文3',
round(sum(CASE WHEN 语文>=70.5 THEN 语文 ELSE 0 END)/count(1)*100,2) as 优秀率,
round(sum(CASE WHEN 语文>=58 THEN 语文 ELSE 0 END)/count(1)*100,2) as 良好率,
round(sum(CASE WHEN 语文>=48 THEN 语文 ELSE 0 END)/count(1)*100,2) as 及格率,
round(avg(语文),2) as 平均分
from cj
where 班级='26'
------解决方案--------------------
select '语文3',
round(sum(CASE WHEN 语文>=70.5 THEN 1 ELSE 0 END)/count(1)*100,2) as 优秀率, round(sum(CASE WHEN 语文>=58 THEN 1 ELSE 0 END)/count(1)*100,2) as 良好率, round(sum(CASE WHEN 语文>=48 THEN 1 ELSE 0 END)/count(1)*100,2) as 及格率,
round(avg(语文),2) as 平均分
from cj where 班级='26'