nikhila reddy
nikhila reddy

Reputation: 63

transposing rows to columns in teradata

I have a table like below

Date_value| Class_ID | count
17-05-2016|1         | 200
17-05-2016|2         | 400
17-05-2016|3         |250
17-05-2016|4         | 300
18-05-2016|1         | 500
18-05-2016|2         | 600
18-05-2016|3         |750
18-05-2016|4         | 800

Now I want the output like below.

Date_value|1   |2   |3    |4
17-05-2016|200 |400 | 250 |300
18-05-2016|500 |600 | 750 |800

Thanks in Advance, Nikhila

Upvotes: 1

Views: 5885

Answers (1)

dnoeth
dnoeth

Reputation: 60462

There's no PIVOT function in Teradata, but this is just some syntax which creates a Select similar to this:

select
   Date_value,
   sum(case when Class_ID = 1 then "count" end as "1",
   sum(case when Class_ID = 2 then "count" end as "2",
   sum(case when Class_ID = 3 then "count" end as "3",
   sum(case when Class_ID = 4 then "count" end as "4",
from tab
group by Date_value

Upvotes: 6

Related Questions