简体   繁体   English

在 SQL 中透视数据 - TERADATA

[英]Pivoting data in SQL - TERADATA

Trying to pivot a table data to get the output shown in the image below.尝试透视表数据以获得下图所示的输出。 Current table ---> Expected table.当前表 ---> 预期表。 Can someone please guide me on this?有人可以指导我吗? enter image description here在此处输入图片说明

Pivot converts the rows of a column to seperate columns and unpivot does the opposite. Pivot 将列的行转换为单独的列,而 unpivot 则相反。 Here, in your case you want the value column to have its data as columns likewise below takes value in pivot and considers each value from IN clause.在这里,在您的情况下,您希望 value 列具有其数据,因为下面的列同样采用数据透视并考虑IN子句中的每个值。

 Select * from table
  Pivot (value for value in
   ('1,234','5,678',...)

Its similar to case when if you want different names to your row data made columns then use case when with group by它类似case when ,如果你想不同的名称来取得列,然后用你的行数据case when与组

  Select value, max(case when 
   value='1234' then value end) as
   Value1, max(case when... End) 
   As value2.. From table group by id;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM