如何对mysql中的数据进行编号
这是对mysql select查询的疑问 让我用一个简单的例子来解释我的疑问 认为这是我的查询 SELECT dbCountry from tableCountry
tableCountry 具有字段 dbCuntryId、dbCountry 和 dbState 我得到了结果,因为
dbCountry india america england kenya pakisthan
我需要结果,因为
1 india 2 america 3 england 4 kenya 5 pakisthan
数字 12345 必须随着数据的增加而生成,并且它不是自动增量 id。 我怎样才能得到它 是不是类似循环的东西
This is a doubt on mysql select query
let me axplain my doubt with a simple example
consider this is my querySELECT dbCountry from tableCountry
tableCountry has fields dbCuntryId, dbCountry and dbState
I have the result as
dbCountry india america england kenya pakisthan
I need the result as
1 india 2 america 3 england 4 kenya 5 pakisthan
the numbers 12345 must be generated with the increase in data and it is not an autoincrement id.
How can i get it
is it something like loop
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以试试这个:
You can try this:
以下应该可以满足您的需要。它使用一个为每行递增并返回的变量:
如果您希望结果始终保持相同的顺序,则需要向查询添加 order by 约束,例如 ORDER BY c.dbCountry 按国家/地区名称排序。
The following should do what you need. It uses a variable that is incremented and returned for each row:
If you want the result to always be in the same order you'll need to add an order by constraint to the query, for example,
ORDER BY c.dbCountry
to order by the country name.