Reputation: 191
How to divide a table in several parts by row number? Condition might look like this:
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
Upvotes: 1
Views: 2203
Reputation: 674
You can use the ROW_NUMBER()
in the QUALIFY
clause. It would be something like this
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;
You can create your tables with those queries. Consider that the ORDER BY
option must be some combination that make the row unique in order to have consistent results.
Upvotes: 7