Table:spa
Student(Sno,Sname,Sage,Ssex)
Course(Cno,Cname,Teacher)
SC(Sno,Cno,Grade)db
SQL:ab
SELECT S.Sname ,C.Cname,D.Grade
FROM Student S,Course C,
(
--這部分是關鍵:
SELECT *
FROM dbo.SC SCA
WHERE grade IN
(
SELECT DISTINCT TOP 2 grade
FROM SC
WHERE SCA.Cno=Cno
ORDER BY Grade DESC
)
) AS DWHERE S.Sno=D.Sno AND C.Cno=D.CnoORDER BY D.Cno ASC