码迷,mamicode.com
首页 > 数据库 > 详细

mysql 练习

时间:2020-02-23 19:50:18      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:select   tps   avg   练习   name   https   group   形式   core   

原文地址 https://www.cnblogs.com/coder-wf/p/11128033.html

对某些题可以精简

-- 18.查询各科成绩最高分、最低分和平均分:以如下形式显示:课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率
-- 及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90

SELECT Course.c_id, Course.c_name, MAX(Score.s_score), MIN(Score.s_score), AVG(Score.s_score) ,
(SELECT COUNT(1) FROM Score WHERE s_score >= 60 AND Score.c_id = Course.c_id)/(SELECT COUNT(1) FROM Score WHERE Score.c_id = Course.c_id) AS ‘及格率‘,
(SELECT COUNT(1) FROM Score WHERE s_score >= 70 AND Score.c_id = Course.c_id)/(SELECT COUNT(1) FROM Score WHERE Score.c_id = Course.c_id) AS ‘中等率‘,
(SELECT COUNT(1) FROM Score WHERE s_score >= 80 AND Score.c_id = Course.c_id)/(SELECT COUNT(1) FROM Score WHERE Score.c_id = Course.c_id) AS ‘优良率‘,
(SELECT COUNT(1) FROM Score WHERE s_score >= 90 AND Score.c_id = Course.c_id)/(SELECT COUNT(1) FROM Score WHERE Score.c_id = Course.c_id) AS ‘优秀率‘
FROM Course LEFT JOIN Score ON
Course.c_id = Score.c_id
GROUP BY Course.c_id

mysql 练习

标签:select   tps   avg   练习   name   https   group   形式   core   

原文地址:https://www.cnblogs.com/myd620/p/12353409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!