如何在SQLite中向行视图添加行号列?

时间:2016-07-29 04:51:06

标签: sqlite views rowid

在SQLite中,我可以使用

将行号列添加到任意表中
select rowid,* from tab;

例如 -

sqlite> create table tab(content);
sqlite> insert into tab values('first row');
sqlite> insert into tab values('second row');
sqlite> insert into tab values('third row');
sqlite> select * from tab;
content
first row
second row
third row
sqlite> select rowid,* from tab;
rowid|content
1|first row
2|second row
3|third row

然而,这种技术不适用于视图 -

sqlite> create view v(content) as select 'first row' union select 'second row' union select 'third row';
sqlite> select * from v;
content
first row
second row
third row
sqlite> select rowid,* from v;
rowid|content
|first row
|second row
|third row

在上面的玩具示例中,我可以在创建视图v时添加行号列,但在实际使用中,我的视图通常是更复杂的表连接或递归CTE。如何在任意视图中添加行号列?

0 个答案:

没有答案
相关问题