From 10a4acf1013574608a0c954925481b0219388b89 Mon Sep 17 00:00:00 2001 From: smallkun Date: Tue, 25 Feb 2025 09:29:35 +0800 Subject: [PATCH] Auto commit --- 2207/MySQL练习题/查询练习.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/2207/MySQL练习题/查询练习.md b/2207/MySQL练习题/查询练习.md index 7057fc6..e66f589 100644 --- a/2207/MySQL练习题/查询练习.md +++ b/2207/MySQL练习题/查询练习.md @@ -311,10 +311,26 @@ HAVING GROUP_CONCAT(sc.course_id) = ( ); #10.查询没学过"张三"老师讲授的任一门课程的学生姓名 +SELECT s.`name` +FROM students s +WHERE s.id NOT IN ( + SELECT st.id + FROM teachers t, courses c, students st, scores sc + WHERE t.id = c.teacher_id AND t.`name` = '张三' AND st.id = sc.student_id AND sc.course_id = c.id +); #11.查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩 +SELECT sc.student_id, st.`name`,AVG(sc.score) +FROM scores sc, students st +WHERE sc.score < 60 AND sc.student_id = st.id +GROUP BY sc.student_id +HAVING COUNT(*) >= 2; #12.检索" 01 "课程分数小于 60,按分数降序排列的学生信息 +SELECT st.* +FROM scores sc, students st +WHERE sc.course_id = '01' AND sc.score < 60 AND sc.student_id = st.id +ORDER BY sc.score DESC; #13.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩