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
现有学生表,数据如下
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