我目前在一个数据库类,在这个问题上被困在3号。
问题2大学数据库具有以下关系:
学生(sno:int,sname:varchar(64),性别:'f'或'm',年龄:int)
课程(cno:int,cname:varchar(32)),
注册(sno:int,cno:int,grade:int)。
编写SQL语句以执行以下任务:
找出最年轻学生的名字。
查找至少注册了CNO=1和CNO=3课程的学生的SNO。
找出参加所有课程的学生的名字。
找出参加三门以上课程的学生的名字。
找出每门课程的名称和平均成绩。
找出“DBMS”课程成绩高于平均成绩的学生的姓名。
最佳答案
三
SELECT S.Sname
FROM Students AS S INNER JOIN Enrollment AS E ON S.Sno = E.Sno
GROUP BY S.Sno, S.Sname
HAVING COUNT(*) = (SELECT COUNT(*) FROM Courses)
4个
SELECT S.Sname
FROM Students AS S INNER JOIN Enrollment AS E ON E.Sno = S.Sno
GROUP BY S.Sno, S.Sname
HAVING COUNT(*) > 3
5个
SELECT C.CName, AVG(E.Grade) AS AvgGrade
FROM Courses AS C INNER JOIN Enrollment AS E ON C.CNo = E.CNo
GROUP BY C.Cno, C.CName