【sql: 练习题 30,31】查询存在不及格的课程,查询课程编号为 01 且课程成绩在 80 分及以上的学生的学号和姓名

题目30:查询存在不及格的课程

分析:直接 查询 student_score  score<60 得到courseid  这样的话 courseid会有很多重复的,要用到distinct 关键字、

SELECT DISTINCT student_course.coursename FROM student_score,student_course WHERE
student_score.score<60 AND student_score.courseid = student_course.id

31:查询课程编号为 01 且课程成绩在 80 分及以上的学生的学号和姓名

分析:这个直接就是联合查询

SELECT student.id, student.stdentname FROM student, student_score WHERE student_score.courseid = 01
AND student_score.score >=80 AND student.id = student_score.studentid

原文地址:https://www.cnblogs.com/yuanyuan2017/p/11377050.html