只有一张表,自关联 ,比较分数,取前两名
SELECT * FROM stuscore A WHERE (SELECT COUNT(DISTINCT score) FROM stuscore B WHERE A.subject = B.subject AND B.score>=A.score)<=2 ORDER BY A.score DESC;
如果成绩相同的第二名有两个会都展示出来
只有一张表,自关联 ,比较分数,取前两名
SELECT * FROM stuscore A WHERE (SELECT COUNT(DISTINCT score) FROM stuscore B WHERE A.subject = B.subject AND B.score>=A.score)<=2 ORDER BY A.score DESC;
如果成绩相同的第二名有两个会都展示出来
转载于:https://www.cnblogs.com/lyon91/p/8920580.html