Auto commit
This commit is contained in:
parent
669136154c
commit
cbfc0a1669
@ -448,21 +448,55 @@ FROM students s
|
|||||||
WHERE YEAR(s.birth) = 1990;
|
WHERE YEAR(s.birth) = 1990;
|
||||||
|
|
||||||
#25.查询每门课程的平均成绩,结果按平均成绩降序排列,平均成绩相同时,按课程编号升序排列
|
#25.查询每门课程的平均成绩,结果按平均成绩降序排列,平均成绩相同时,按课程编号升序排列
|
||||||
|
SELECT c.`name`, AVG(s.score) avg
|
||||||
|
FROM scores s, courses c
|
||||||
|
WHERE s.course_id = c.id
|
||||||
|
GROUP BY c.id;
|
||||||
|
ORDER BY avg DESC, c.id;
|
||||||
|
|
||||||
#26.查询平均成绩大于等于 85 的所有学生的学号、姓名和平均成绩
|
#26.查询平均成绩大于等于 85 的所有学生的学号、姓名和平均成绩
|
||||||
|
SELECT st.id, st.`name`, AVG(sc.score) avg
|
||||||
|
FROM students st, scores sc
|
||||||
|
WHERE st.id = sc.student_id
|
||||||
|
GROUP BY st.id
|
||||||
|
HAVING avg>85;
|
||||||
|
|
||||||
#27.查询课程名称为「数学」,且分数低于 60 的学生姓名和分数
|
#27.查询课程名称为「数学」,且分数低于 60 的学生姓名和分数
|
||||||
|
SELECT st.`name`, sc.score
|
||||||
|
FROM students st, scores sc, courses c
|
||||||
|
WHERE st.id = sc.student_id AND sc.course_id = c.id
|
||||||
|
AND c.`name` = '数学' AND sc.score < 60;
|
||||||
|
|
||||||
#28.查询所有学生的课程及分数情况(存在学生没成绩,没选课的情况)
|
#28.查询所有学生的课程及分数情况(存在学生没成绩,没选课的情况)
|
||||||
|
SELECT st.`name` '学生姓名', c.`name` '课程名', sc.score
|
||||||
|
FROM students st
|
||||||
|
LEFT JOIN scores sc ON st.id = sc.student_id
|
||||||
|
LEFT JOIN courses c ON c.id = sc.course_id;
|
||||||
|
|
||||||
#29.查询任何一门课程成绩在 70 分以上的姓名、课程名称和分数
|
#29.查询任何一门课程成绩在 70 分以上的姓名、课程名称和分数
|
||||||
|
SELECT st.`name` '学生姓名', c.`name` '课程名', sc.score
|
||||||
|
FROM students st
|
||||||
|
LEFT JOIN scores sc ON st.id = sc.student_id
|
||||||
|
LEFT JOIN courses c ON c.id = sc.course_id
|
||||||
|
WHERE sc.score >= 70;
|
||||||
|
|
||||||
#30.查询不及格的课程
|
#30.查询不及格的课程
|
||||||
|
SELECT st.`name` '学生姓名', c.`name` '课程名', sc.score
|
||||||
|
FROM students st
|
||||||
|
LEFT JOIN scores sc ON st.id = sc.student_id
|
||||||
|
LEFT JOIN courses c ON c.id = sc.course_id
|
||||||
|
WHERE sc.score < 60;
|
||||||
|
|
||||||
#31.查询课程编号为 01 且课程成绩在 80 分以上的学生的学号和姓名
|
#31.查询课程编号为 01 且课程成绩在 80 分以上的学生的学号和姓名
|
||||||
|
SELECT st.`name` '学生姓名', c.`name` '课程名', sc.score
|
||||||
|
FROM students st
|
||||||
|
LEFT JOIN scores sc ON st.id = sc.student_id
|
||||||
|
LEFT JOIN courses c ON c.id = sc.course_id
|
||||||
|
WHERE sc.score > 80 AND c.id = '01';
|
||||||
|
|
||||||
#32.求每门课程的学生人数
|
#32.求每门课程的学生人数
|
||||||
|
|
||||||
|
|
||||||
#33.成绩不重复,查询选修「张三」老师所授课程的学生中,成绩最高的学生信息及其成绩
|
#33.成绩不重复,查询选修「张三」老师所授课程的学生中,成绩最高的学生信息及其成绩
|
||||||
|
|
||||||
#34.成绩有重复的情况下,查询选修「张三」老师所授课程的学生中,成绩最高的学生信息及其成绩
|
#34.成绩有重复的情况下,查询选修「张三」老师所授课程的学生中,成绩最高的学生信息及其成绩
|
||||||
|
Loading…
x
Reference in New Issue
Block a user