首先,我不是在问如何在返回结果后获得当前行号。
我想知道,是否可以将行号作为MySQL结果中返回的列之一?我正在尝试做的是添加一个数字来递增,直到每一行。如下所示:
| id | myNum | name |
+----+-------+------+
| 34 | 1 | John |
| 24 | 2 | Alex |
| 56 | 3 | Brad |
etc...我猜它会涉及存储过程,但我想知道没有它们是否可能……
发布于 2012-02-15 07:21:26
select table.*,@rn:=@rn+1 as row_num
from table,(select @rn:=0) as r order by field_you_like发布于 2012-02-15 07:22:46
select @n := @n + 1 mynum, t.*
from (select @n:=0) initvars, tbl thttps://stackoverflow.com/questions/9285660
复制相似问题