Need help in returning two adjacent rows as one row

General

Need help in returning two adjacent rows as one row

Hi,

  I am new to teradata. I have a requirement where i have to write two adjacent rows in a table as a row in a new table.

 Can somebody please help me.

My source table:

============

A

B

C

D

E

Target table should look like this:

=================

A B

B C

C D

D E

2 REPLIES
Enthusiast

Re: Need help in returning two adjacent rows as one row

Try this Query, i think it will work...

sel t.Col,tt.Col from (sel Col, row_number() over(order by Col) RN from Tablename)t

join

(sel Col, row_number() over(order by Col)-1 RN1 from Tablename)tt

on t.RN=tt.RN1

Enthusiast

Re: Need help in returning two adjacent rows as one row

In another 2 method,

1. select c1,min(c1)over(order by c1 rows 1 following and 1 following) as c2 from table qualify c2 is not null;

2. select c1,coalesce(min(c1)over(order by c1 rows 1 following and 1 following),'No adjacent cell') as c2 from

    table;

Regards,

Mohan