Query each class of the top three scores

select s1.class,s1.`name`,s1.score 
from sc s1 where 
(
SELECT COUNT(1) FROM sc s2 where s1.class=s2.class AND s2.score >= s1.score
)<=3 GROUP BY s1.class,s1.score DESC;

sc table

Here Insert Picture Description

search result

Here Insert Picture Description

Published 23 original articles · won praise 1 · views 3135

Guess you like

Origin blog.csdn.net/qq_43669912/article/details/99685495