All Forums Analytics
wiyanaananta 4 posts Joined 06/13
01 Feb 2015
Using Case When on Teradata

Dear Master,
 
I have data 
Date,Col1, Col2
20150101, A, 23
20150101, B, 20
20150102, A, 19
20150102, C, 5
 
If I want get result
Col2, 20150101, 20150102
A, 23, 19
B, 20,
C, ,5
 
How to using "case when" on teradata? I confiused when its work for join col2
 
Thank you before,
 
wiyana ananta
 

dnoeth 4628 posts Joined 11/04
02 Feb 2015

Hi Wiyana,
is the date hard-coded?
 

SELECT 
   Col1
  ,MAX(CASE WHEN DATE = 20150101 THEN col2 END)
  ,MAX(CASE WHEN DATE = 20150102 THEN col2 END)
FROM tab
GROUP BY 1

 

Dieter

wiyanaananta 4 posts Joined 06/13
05 Feb 2015

Hi Dieter,
yes I use hard code because only for monthly query.
Thank You, its work

You must sign in to leave a comment.