我知道这个问题已被问了很多时间,但我一直没能找到解决方案与我的数据结构。然而,我遇到了以下文章An Alternative (Better?) Method to UNPIVOT (SQL Spackle)。Unpivot SQL OR使用行数据作为列标题和行数据交叉应用表格作为列数据
我有以下表的原始数据结果如下
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行的包,该怎么办? – Serg