bin456789
2016-11-15 03:33:15 +08:00
1:
WITH a AS ( SELECT dbo.student.sname ,
dbo.course.cname ,
dbo.SC.score ,
RANK() OVER ( PARTITION BY dbo.SC.cid ORDER BY score DESC ) AS rank
FROM SC
INNER JOIN course ON SC.cid = dbo.course.cid
INNER JOIN student ON student.sid = dbo.SC.sid
)
SELECT *
FROM a
WHERE rank <= 3;
2:
WITH a AS ( SELECT * ,
ROW_NUMBER() OVER ( ORDER BY c ) AS num
FROM dbo.T
)
SELECT *
FROM a
WHERE num >= 11
AND num <= 20;