Mysql 单表查询各班级总分前三名

2025-03-13 20:06:48
推荐回答(2个)
回答1:

select class,total,name from (select *,ywsc+sxsc as total from st ORDER BY total DESC) b
where
not EXISTS(select * from (select *,ywsc+sxsc as total from st ORDER BY total DESC) c where c.class=b.class and b.total < c.total GROUP BY c.class HAVING COUNT(*)>2 )
ORDER BY b.class,b.total DESC

回答2:

表结构给出来