postgresql 如何在 Redshift 中创建行号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24436078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:31:13 来源:igfitidea点击:
How do I create row numbers in Redshift?
提问by d_a_c321
I would like to create a table using a select statement and add a column with row numbers
我想使用 select 语句创建一个表并添加一个带有行号的列
So I'd like to write something like:
所以我想写一些类似的东西:
create table schema.table_w_rownumbers as
select
identity(1, 1) as nrum,
foo.*
from schema.initial_table as foo;
回答by user 923227
This worked for me!
这对我有用!
create table schema.table_w_rownumbers as
select
row_number() over (partition by 1) as nrum,
foo.*
from schema.initial_table as foo;
回答by SQLChao
Try this code. Make sure you change order by id
to whatever it needs to be ordered by.
试试这个代码。确保您更改order by id
为需要订购的任何内容。
Create Table schema.table_w_rownumbers
AS
(
select row_number() over (order by id) as nrum, * schema.initial_table
);