Using Case When on Teradata

Analytics

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

2 REPLIES
Senior Apprentice

Re: Using Case When on Teradata

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

Re: Using Case When on Teradata

Hi Dieter,

yes I use hard code because only for monthly query.

Thank You, its work