在查询中添加行号 [英] Adding a Row Number in Query
本文介绍了在查询中添加行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Access 2013的数据库中有一个表.
I have a table in my database in Access 2013.
Table : city
ID_city city
1 Tetuan
5 Rabat
9 Marrakech
10 Agadir
15 Laayoun
我希望在它们旁边添加Rowid号:
I wish to add the Rowid number beside them:
Rowid ID_city city
1 1 Tetuan
2 5 Rabat
3 9 Marrakech
4 10 Agadir
5 15 Laayoun
推荐答案
一种方法是在子查询中使用count
函数.不确定它是否可以很好地扩展,并且可能有更好的方法...
One way to do this is to use the count
function in a subquery. Not sure it scales well though and there are probably better ways...
select
(select count(*) from city where ID_city <= t1.ID_city) as row_number,
*
from city t1
这篇关于在查询中添加行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文