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

Rewriting the Self join - response (4) by ulrich

$
0
0

This should create also the same output an would do the self join only once but comes with a smal prod join

SELECT
	case when c.id = 1 then A.MERGE_ID else B.REM_ID end,
	case when c.id = 1 then A.REM_ID else B.REM_ID end, 
	case when c.id = 1 then A.EFF_DT else B.EFF_DT end, 
	case when c.id = 1 then A.FIRST_MERGE_DT else B.FIRST_MERGE_DT end , 
	case when c.id = 1 then A.CURR_CUST_MERGE_DT else b.CURR_CUST_MERGE_DT end 
FROM CUST_HIST A
     INNER JOIN
     CUST_HIST B 
     	ON A.REM_ID=B.MERGE_ID
     CROSS JOIN 
     (select calendar_date - current_date as id from sys_calendar.calendar where id in (1,2)) as c
group by 1,2,3,4,5

 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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