【发布时间】:2017-06-29 11:05:54
【问题描述】:
我知道这个问题已经被问过很多次了,但我无法用我的数据结构找到解决方案。然而,我确实遇到了以下文章An Alternative (Better?) Method to UNPIVOT (SQL Spackle)。
我有下表,原始数据结果如下
RowType | LocalDate | UTCDate | Target1 | Target2 | Target3
KPIName NULL NULL Feed1 Feed2 Feed3
Balance NULL NULL Product Reagent Water
UoM NULL NULL t t %
ActiveDate 2017-01-01 2016-12-31 5.0 3.2 20
我想要达到的结果如下
KPIName | Balance | ActiveDate | UTCDate | UoM | Value
Feed1 Product 2017-01-01 2016-12-31 t 5.0
Feed2 Reagent 2017-01-01 2016-12-31 t 3.2
Feed3 Water 2017-01-01 2016-12-31 % 20
【问题讨论】:
-
我看不到对行进行分组的方法。如果在另一个日期再添加一个 4 行包怎么办?
标签: sql sql-server transpose unpivot cross-apply