将行转置为 teradata 中的列
transposing rows to columns in teradata
我有一个 table 如下所示
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
提前致谢,
尼基拉
Teradata 中没有 PIVOT 函数,但这只是一些创建 Select 类似于此的语法:
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
我有一个 table 如下所示
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
提前致谢, 尼基拉
Teradata 中没有 PIVOT 函数,但这只是一些创建 Select 类似于此的语法:
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