如何在SQL Teradata中转置表

问题描述 投票:0回答:1

我在Teradata中有这个表,有这个查询:

select column1, column2,column3 from squema.table;

column1 column2 column3 count
ab1      ab2    tip1    123
ab1      ab2    tip2    23
ab1      ab2    tip3    5

我正在尝试转置,但我没有找到一个很好的样本来获取Teradata中的这个表:

column1 column2  tip1  tip2 tip3 
ab1      ab2      123    23   5

谢谢你的帮助。

sql teradata query-performance
1个回答
2
投票

用例何时

   select column1, column2,max(case when column3='tip1' then count end) as tip1  
    ,
    max(case when column3='tip1' then count end) as tip2,
    max(case when column3='tip1' then count end) as tip3
     from squema.table group by column1, column2
© www.soinside.com 2019 - 2024. All rights reserved.