我知道這個問題已被問了很多時間,但我一直沒能找到解決方案與我的數據結構。然而,我遇到了以下文章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