Overseer10
Overseer10

Reputation: 361

Teradata Auto-Increment Query

Can Teradata SQL Query do Auto-Increment?

I'm looking for something similar to

SELECT
  Date (Auto-Increment by 1 over Column 2),
  Column 2,
  Column 3
FROM Fake_Table
GROUP BY 1,2,3

And get something such as

Date        Column 2    Column 3
2012-06-11  A           A
2012-06-11  A           B
2012-06-11  A           C
2012-06-12  B           A
2012-06-13  C           B

Is this possible?

Upvotes: 0

Views: 3398

Answers (1)

Rob Paller
Rob Paller

Reputation: 7786

You should be able to use the ROW_NUMBER() window aggregate with a PARTITION BY and ORDER BY statement to provide you a seed value to add to the DATE.

Pseudo-Code:

SELECT
  CURRENT_DATE + ROW_NUMBER() OVER(PARTITION BY Column2,
                                   ORDER BY Column2)       AS MyDate
  Column2,
  Column3
FROM Fake_Table
GROUP BY 1,2,3

Upvotes: 3

Related Questions