展开全部
创建数据表create table test
(username varchar(10),
type int);
insert into test values ('aaa',1);
insert into test values ('bbb',1);
insert into test values ('ccc',2);
insert into test values ('ddd',2);
insert into test values ('eee',3);
执行62616964757a686964616fe78988e69d8331333335333665select s.username,s.type
from
(select username,type,rank
from
(select t.username,t.type,@rownum:=@rownum+1,
if (@type=t.type,@rank:=@rank+1,@rank:=1) as rank,
@type:=t.type
from(
select username,type from test order by type) t,
(select @rownum:=9,@type:=null,@rank:=0) a
) result) s
where s.rank=1
结果截图