数据库中存在一个表A(课程标识为bid,分数为score),请写出查询语句,求出该表中每门课程中分数在70到80分之间的人数占本门课程全部人数的比例!
------解决思路----------------------
select bid,
sum(case
when score >= 70 and score <= 80 then
1
else
0
end) / count(score) percent
from a
group by bid
------解决思路----------------------
楼主,你所说的70到80分之间是指70~80,还是70-79?
1.70~79
select bid,round(sum(case when score >= 70 and score < 80 then 0)/count(*)*100,2)
------解决思路----------------------
'%' percent from A group by bid
2.70~79
select bid,round(sum(case when score >= 70 and score < 80 then 0)/count(*)*100,2)
------解决思路----------------------
'%' percent from A group by bid