select * from ( select if(@utype = a.utype, @nu := @nu+1, @nu:=1) as nu, @utype := a.utype, a.* from secuser a order by a.utype,a.id desc ) T where T.nu <= 5
mysql分组取前5,类似sql server的partition by
原文:https://www.cnblogs.com/bingco/p/14597905.html