在Teradata SQL中创建伪索引列

时间:2017-06-22 19:33:38

标签: sql teradata

我有声明:

SELECT col_a, col_b, col_c from database.table sample 50;

我希望我的输出看起来像这样:

id   col_a   col_b   col_c
1    data    goes    here
2    data    goes    here
3    data    goes    here
4    data    goes    here
5    data    goes    here
6    data    goes    here

基本上 - 我需要为id创建一个从1开始的列,并在检索到的每一行时自动递增。

我该怎么做?

2 个答案:

答案 0 :(得分:2)

如果您确实希望编号的采样行:

Error: NO JSON file matched with specific pattern: appsettings.json

而不是SELECT ROW_NUMBER() OVER (ORDER BY some_field), dt.* FROM ( SELECT col_a, col_b, col_c FROM database.table SAMPLE 50 ) AS dt 你也可以使用SAMPLE,但它不再是随机的。

答案 1 :(得分:0)

您可以使用row_number()

select row_number() over (order by ??) as id, col_a, col_b, col_c
from t;

??代表给出id排序的列/表达式。