mysql查询各种类前N条数据

现有学生表,数据如下

scroces分数,grade为年级。先需要查询每个年级分数前一的学生详细数据

sql:

select * from test.student as a
where (select count(1) from test.student b where a.grade = b.grade and b.scroces > a.scroces) <1
order by a.grade,a.scroces

 

posted on 2022-02-14 10:16  沧海一目  阅读(169)  评论(0)    收藏  举报

导航