user3451371
user3451371

Reputation: 39

Use the value of next row in teradata

I have this table with the following data:

ID  NUM1    NUM2
A   1000    1001
B   1001    1004
C   1006    1007

I want an out put like this :

ID  NUM1    NUM2    NUM3
A   1000    1001    1001
B   1001    1004    1006
C   1006    1007    1007

Could you please help me in achieving this.

Upvotes: 0

Views: 4922

Answers (1)

dnoeth
dnoeth

Reputation: 60462

There's no LAG/LEAD function in Teradata but you can rewrite it:

select ID, NUM1, NUM2
   coalesce(min(NUM1) -- next row's value
            over (order by ID
                  rows between 1 following and 1 following)
           , NUM2)    -- or current value when there's no next row
from tab

Upvotes: 2

Related Questions