将行转换为teradata中的列

时间:2016-05-18 10:59:07

标签: teradata

我有一张如下表格

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

现在我想要输出如下。

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

先谢谢, Nikhila

1 个答案:

答案 0 :(得分:5)

Teradata中没有PIVOT功能,但这只是一些语法,可以创建类似于此的选择:

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