Table:
Student(Sno,Sname,Sage,Ssex)
Course(Cno,Cname,Teacher)
SC(Sno,Cno,Grade)
SQL:
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 D
WHERE S.Sno=D.Sno AND C.Cno=D.Cno
ORDER BY D.Cno ASC