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

find the min & max value for the below query - response (2) by Gowtham

$
0
0

CREATE SET TABLE RETAIL.tab ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
pil1 VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC,
pil2 VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC,
timp VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC,
mdat DATE FORMAT 'YYYY-MM-DD',
inti INTEGER)
PRIMARY INDEX ( pil1 );

ins tab('3Week','3Month','1Year',1130927,40);
ins tab('1Week','1Month','1Year',1130927,40);
ins tab('1Week','1Month','6Month',1130327,42);
ins tab('1Week','1Month','2Week',1121011,44);
ins tab('1Week','1Month','9Month',1130627,45);
ins tab('1Week','1Month','1Month',1121027,46);
ins tab('1Week','1Month','Overnight',1120927,47);
ins tab('1Week','1Month','3Month',1121227,43);
ins tab('1Week','1Month','1Week',1121004,41);
ins tab('1Week','8Month','1Year',1130927,40);

run the below query

sel 1 sno, A.pil1,A.pil2, B.timp,B.mdat,B.inti from tab A left join tab B
on A.pil1=B.timp group by 1,2,3,4,5,6
union all
sel 2, A.pil1,A.pil2, C.timp,C.mdat,C.inti from tab A left join tab C
on A.pil2=C.timp group by 1,2,3,4,5,6

result is

1 1Week 1Month 1Week 10/4/2012 41
1 1Week 8Month 1Week 10/4/2012 41
1 3Week 3Month ? ? ?
2 1Week 8Month ? ? ?
2 3Week 3Month 3Month 12/27/2012 43
2 1Week 1Month 1Month 10/27/2012 46

for Sno 1, PIL1 column value is 3week, i want less than 3week from TIMP column, so the value is 2week.
for Sno 2, PIL1 column value is 8month, i want greater than 8month from TIMP column, so the value is 1year, see the fields bolded in my expected result.


Viewing all articles
Browse latest Browse all 27759

Trending Articles



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