Questions tagged «unpivot»

6
SQL Server:列到行
寻找优雅的(或任何)解决方案以将列转换为行。 这是一个示例:我有一个具有以下架构的表: [ID] [EntityID] [Indicator1] [Indicator2] [Indicator3] ... [Indicator150] 这是我想要得到的结果: [ID] [EntityId] [IndicatorName] [IndicatorValue] 结果值为: 1 1 'Indicator1' 'Value of Indicator 1 for entity 1' 2 1 'Indicator2' 'Value of Indicator 2 for entity 1' 3 1 'Indicator3' 'Value of Indicator 3 for entity 1' 4 2 'Indicator1' 'Value of …
128 sql  sql-server  tsql  unpivot 

4
取消透视列名称
我有一张StudentMarks有栏的桌子Name, Maths, Science, English。数据就像 Name, Maths, Science, English Tilak, 90, 40, 60 Raj, 30, 20, 10 我想像下面这样安排它: Name, Subject, Marks Tilak, Maths, 90 Tilak, Science, 40 Tilak, English, 60 使用unpivot,我可以正确获取Name,Marks,但无法将源表中的列名获取到Subject所需结果集中的列。 我该如何实现? 到目前为止,我已经到达以下查询(获取名称,商标) select Name, Marks from studentmarks Unpivot ( Marks for details in (Maths, Science, English) ) as UnPvt
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.