查询出只选修两门课程的学生和姓名SELECT DISTINCT student.SId, student.SnameFROM student, (SELECT sc.SId, COUNT(*) as aFROM scGROUP BY(sc.SId)) as AWHERE student.SId = A.SIdAND A.a = 2SELECT Distinct student.Sid, student.SnameFROM studentwhere student.SId in (SELECT sc.SIdFROM scGROUP BY sc.SIdhaving count(*)=2)查询男生、女生人数SELECT Ssex, count(*)FROM studentGROUP BY student.Ssex查询名字中含有「风」字的学生信息SELECT *FROM studentWHERE student.sname LIKE '%风%';查询同名同姓学生名单,并统计同名人数SELECT Sname, count(*)FROM studentGROUP BY SnameHAVING COUNT(*) >1;查询 1990 年出生的学生名单SELECT *FROM studentWHERE sage LIKE '1990-%';查询每门课程的平均成绩,结果按平均成绩降序排列,平均成绩相同时,按课程编号升序排列SELECT sc.CId, avg(sc.score) as avgscoreFROM scGROUP BY sc.CIdORDER BY avg(sc.score) DESC, sc.CId查询平均成绩大于等于 85 的所有学生的、姓名和平均成绩SELECT student.Sid, student.Sname, t.avgscoreFROM student, (SELECT sc.SId, avg(sc.score) as avgscoreFROM scGROUP BY sc.SId) as tWHERE student.SId = t.SIdAND t.avgscore >= 85查询课程名称为「数学」,且分数低于 60 的学生姓名和分数SELECT student.Sname, t.scoreFROM student, (SELECT sc.SId, sc.scoreFROM scWHERE sc.score < 60AND sc.CId = (SELECT CId FROM course WHERE course.Cname='数学')) as tWHERE student.SId = t.SId查询所有学生的课程及分数情况(存在学生没成绩,没选课的情况)SELECT st.*, sc.CId, sc.scoreFROM student AS stLEFT JOIN scON st.SId = sc.SIdORDER BY st.SId, sc.CId;查询任何一门课程成绩在 70 分以上的姓名、课程名称和分数SELECT student.Sname, course.Cname, sc.scoreFROM student, course, scWHERE student.SId = sc.SIdAND course.CId = sc.CIdAND sc.score > 70ORDER BY sc.CId查询不及格的课程SELECT sc.CId, sc.scoreFROM scWHERE sc.score <60ORDER BY sc.CId;