我有一些简单的查询:
SELECT foo, bar FROM table
我想你现在的结果是什么样的.
i think you now whats the result looks like.
我想要做的是根据查询结果中出现的数据数量来显示一些序列号.它就像 AUTO_INCREMENT
(这并不意味着我想显示 ID).我想要的结果是这样的:
What I want to do is to show some sequential number based on how many data appear from query result. its just like AUTO_INCREMENT
(its not mean i want to show ID).
The result what I want is like:
|No| foo | bar |
-------------------------
|1 | bla | 123 |
|2 | boo | abc |
|3 | wow | xxx |
我该怎么做才能做到?
提前致谢
select @rownum:=@rownum+1 No, foo, bar from table, (SELECT @rownum:=0) r;
这篇关于如何在 MySQL 查询结果中显示序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!