一道数据库面试题,大家帮忙看看!

疯狂的指针 2015-06-18 05:41:31
数据库中存在一个表A(课程标识为bid,分数为score),请写出查询语句,求出该表中每门课程中分数在70到80分之间的人数占本门课程全部人数的比例!
...全文
132 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
疯狂的指针 2015-06-19
  • 打赏
  • 举报
回复
引用 4 楼 碧水幽幽泉的回复:

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~80
select bid,round(sum(case when score >= 70 and score <= 80 then 0)/count(*)*100,2)||'%'  percent 
  from A 
group by bid

大于等于70,小于等于80,谢谢你的解答,受教了!
碧水幽幽泉 2015-06-18
  • 打赏
  • 举报
回复

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~80
select bid,round(sum(case when score >= 70 and score <= 80 then 0)/count(*)*100,2)||'%'  percent 
  from A 
group by bid

碧水幽幽泉 2015-06-18
  • 打赏
  • 举报
回复

2.70~80
select  bid,round(sum(case when score >= 70 and score <= 80 then 0)/count(*)*100,2)||'%'  percent from A group by bid
碧水幽幽泉 2015-06-18
  • 打赏
  • 举报
回复
楼主,你所说的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
charlie_coolp 2015-06-18
  • 打赏
  • 举报
回复
select bid, sum(case when score >= 70 and score <= 80 then 1 else 0 end) / count(score) percent from a group by bid

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧