Quantcast
Channel: Teradata Forums - All forums
Viewing all articles
Browse latest Browse all 27759

Sliding Window Syntax - forum topic by johnajorgensen@yahoo.com

$
0
0

I am not positive this is a sliding window problem, but it is my best guess. I would like to show the current rows values and the next row, on the same output record, and then advance to the next recor --, repeat.
 I think the simple example below illustrates my problem.  Given the data in table TEST1, I would like to write a query which gives me output similar to my example.  
On a related note, is there a white paper someone which  explains the usage and idiosyncrasis of Ordered Analytic Functions?  I get really confused reading the docs - so many possibilities and so few brain cells.
 
 

CREATE TABLE TEST1  (

ID INT,

YR CHAR(4),

VAL CHAR(1)

) UNIQUE PRIMARY INDEX PK (ID, YR) ;

 

INSERT TEST1 (ID, YR, VAL) VALUES (1,'2001', 'A');

INSERT TEST1 (ID, YR, VAL) VALUES (1,'2002', 'B');

INSERT TEST1 (ID, YR, VAL) VALUES (1,'2003', 'C');

INSERT TEST1 (ID, YR, VAL) VALUES (1,'2004', 'D');

INSERT TEST1 (ID, YR, VAL) VALUES (2,'2001', 'e');

INSERT TEST1 (ID, YR, VAL) VALUES (2,'2002', 'f');

INSERT TEST1 (ID, YR, VAL) VALUES (2,'2003', 'g');

INSERT TEST1 (ID, YR, VAL) VALUES (2,'2004', 'h');

 

SEL * FROM test1 ORDER BY 1,2;

 

-- desired output of query

ID  Yr  VALUE   Next_year   Next_year_value

1   2001    A   2002    B

1   2002    B   2003    C

1   2003    C   2004    D

2   2001    e   2002    f

2   2002    f   2003    g

2   2003    g   2004    h

 

Thanks a lot,

John J

Forums: 

Viewing all articles
Browse latest Browse all 27759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>