Teradata:如何按行号划分表格?

时间:2017-10-26 13:27:37

标签: sql teradata

如何按行号分几个部分的表格? 条件可能如下所示:

create table part1 as
Select * from table
where row_number between 1 and 1000000

create table part2 as
Select * from table
where row_number between 1000001 and 2000000

THX

1 个答案:

答案 0 :(得分:6)

您可以使用ROW_NUMBER()子句中的QUALIFY。它会是这样的

Select * from table
QUALIFY ROW_NUMBER() OVER(ORDER BY id) BETWEEN 1 and 1000000;

Select * from table
QUALIFY ROW_NUMBER() OVER(ORDER BY id) BETWEEN 1000001 and 2000000;

您可以使用这些查询创建表格。考虑ORDER BY选项必须是某种组合,使行唯一,以便获得一致的结果。