Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

how to find the start dates from history - response (10) by CarlosAL

$
0
0
Sunny: Maybe this approach will help you:   BTEQ -- Enter your SQL request or BTEQ command: SELECT * FROM YOUR_TABLE ORDER BY 1,2; *** Query completed. 8 rows found. 4 columns returned. *** Total elapsed time was 1 second. customer start_date end_date transaction_n -------- ---------- ---------- ------------- A 2008-12-03 2009-10-05 1 A 2009-10-06 2010-01-12 2 A 2010-01-13 2010-01-13 3 A 2010-01-14 9999-12-31 4 B 1991-12-03 2000-10-05 1 B 2000-10-06 2009-01-12 2 B 2011-01-13 2011-06-13 3 B 2011-06-14 9999-12-31 4 BTEQ -- Enter your SQL request or BTEQ command: SELECT customer, start_date, end_date, transaction_n FROM ( SELECT customer, start_date, end_date, transaction_n, MAX(end_date) OVER (PARTITION BY customer ORDER BY start_date ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING ) prev_end_date FROM YOUR_TABLE ) pre WHERE start_date- coalesce(prev_end_date,date '1900-01-01') > 1 QUALIFY ROW_NUMBER() OVER (PARTITION BY customer ORDER BY transaction_n DESC) = 1 ORDER BY 1,2; *** Query completed. 2 rows found. 4 columns returned. *** Total elapsed time was 1 second. customer start_date end_date transaction_n -------- ---------- ---------- ------------- A 2008-12-03 2009-10-05 1 B 2011-01-13 2011-06-13 3   Cheers. Carlos.

Viewing all articles
Browse latest Browse all 14773

Trending Articles



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