方法1:
Select (@i:=@i+1) as RowNum, A.* from Table1 A,(Select @i:=0) B order by a.id desc limit 0, 10;
方法2:
Set @i:=0;
Select (@i:=@i+1) as RowNum, A.* from Table1 A order by a.id desc limit 0,10
以下SQL可在分页中使用:
set @i:=10; select (@i:=@i+1) as RowNum, A.* from Table1 A order by a.id desc limit 10,5