mysql分组取前5,类似sql server的partition by
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

此外记录一下 sqlserver `partition by` 用法:
SELECT col ...n, row_number() over (partition by colx ORDER BY colz) FROM tablename;

浙公网安备 33010602011771号