select tmp.*,@rank:=@rank+1 as rank from ( (select * from jj) tmp, (select @rank :=0) b ) 上面的不行用下面这个 select (@i := @i + 1) as rownum, code from user, (select @i := 0) as init;