MySQL查询结果增加行号

[b]说明:通过增加虚表,设置变量且初始化为0..然后每行取变量+1[/b]

SELECT @rownum:=@rownum+1 as rownum FROM myTable,(select @rownum:=0)t


[b]效果如下图[/b]

[img]http://dl2.iteye.com/upload/attachment/0124/4004/3781cd2c-6d57-348a-bb6a-824cb3d33b5e.png[/img]

你可能感兴趣的:(MySQL)