Updating 2nd row values with 1st row

Database
Enthusiast

Updating 2nd row values with 1st row

Hi  Dieter,

Thank You for your help.

But in the table below COL2 values need to take into consideration as 1 partition.

Can you please  help me to write the query to achieve the below expected result.

COL1 COL2 COL3

1 100 2,000

2 100 3,000

3 100 4,000

4 300 5,000

5 300 6,000

6 300 7,000

Expected result would be:

COL1 COL2 COL3

1 100 3,000

2 100 4,000

3 100 ?

4 300 6,000

5 300 7,000

6 300 ? 

2 REPLIES
Senior Apprentice

Re: Updating 2nd row values with 1st row

Hi Subbu,

you just have to add this condition to the query i posted in:

developer.teradata.com/blog/dnoeth/2013/07/how-to-spell-a-numeric-value-in-english-words#comment-65238

update tab as t
set col3 = (select col3 from tab as t2
where t2.col2 = t.col2
and t2.col1 = t.col1+1)

Dieter

Enthusiast

Re: Updating 2nd row values with 1st row

Its working.Thanks alot Dieter.