56,677
社区成员
发帖
与我相关
我的任务
分享
create table test(a int , b int, c int);
insert into test select 1, 2, 20;
insert into test select 1, 3, 21;
insert into test select 1, 4, 22;
insert into test select 1, 5, 23;
insert into test select 1, 6, 24;
insert into test select 2, 7, 25;
insert into test select 2, 8, 26;
insert into test select 2, 9, 27;
insert into test select 2, 10,28;
insert into test select 2, 11,29;
select a, b, c, if(@a=X.a, @rank:=@rank+1, @rank:=1) as rank, @a:=X.a
from
(select a,b,c from test order by a, b, c) X
select a, b, c, if(@a=X.a, @rank:=@rank+1, @rank:=1) as rank, @a:=X.a
from
(select @a:=null, @rank:=0, a,b,c from test order by a, b, c) X