Grigory P
Grigory P

Reputation: 191

Teradata: how to divide a table by row number?

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

Answers (1)

danielsepulvedab
danielsepulvedab

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

Related Questions