Compare current row with previous NOT NULL row in Teradata.

Tools & Utilities

Compare current row with previous NOT NULL row in Teradata.

Hi,

I need to implement a logic in which i need to compare my current row with previous NOT NULL row. I am using PRECEDING function but didn't get the desired results.

Please find details below.

If my source table is like

Code  Id     Datetime                       Flag1 Flag2 Flag3

GSM 1111 2015-01-01 00:00:04    1        1      1

GSM 1111 2015-01-01 00:00:08    2        2      2

GSM 1111 2015-01-01 00:00:12    NULL  NULL NULL

GSM 1111 2015-01-01 00:00:16    NULL  NULL NULL

GSM 1111 2015-01-01 00:00:20    NULL  NULL NULL

GSM 1111 2015-01-01 00:00:24    3        3      3

GSM 1111 2015-01-01 00:00: 28   4        4      4

GSM 1111 2015-01-01 00:00:32    5        5      5

Then output should be

Code  Id     Datetime                       Flag1 Flag2 Flag3

GSM 1111 2015-01-01 00:00:04    1        1      1

GSM 1111 2015-01-01 00:00:08    2        2      2

GSM 1111 2015-01-01 00:00:12    2        2      2

GSM 1111 2015-01-01 00:00:16    2        2      2

GSM 1111 2015-01-01 00:00:20    2        2      2

GSM 1111 2015-01-01 00:00:24    3        3      3

GSM 1111 2015-01-01 00:00:28    4        4      4

GSM 1111 2015-01-01 00:00:32    5        5      5

Please guide me as i am not able to achieve this logic through PRECEDING function.

Thanks.

Tags (2)