这个sql有点麻烦了,简单点的就直接select id,name,type,score from student where type='小学生' limit 2 union select id,name,type,score from student where type='中学生' limit 2 ;或者你用存储过程来做循环:查询出所有type然后在循环里动态给 查询语句中的type复制,有几个type就concat几个union上去,其他直接写sql查询的话有点难,写不出来
select id,name,age,type,score from(select id,name,age,type,score,rank() over(partition by school order by id asc) as num from table aa)where aa.num<3这个可以我试过了