小编典典

SQL:“Reverse”转置表

sql

下表显示了很多有关移调的问题…

scanid | region | volume
-------------------------
1          A      34.4
1          B      32.1
1          C      29.1
2          A      32.4
2          B      33.2
2          C      35.6

到这张表。

scanid | A_volume | B_volume | C_volume
----------------------------------------
1        34.4         32.1      29.1
2        32.4         33.2      35.6

但是,我需要做相反的事情,并且难以解决这个问题。有人可以帮忙吗?

谢谢你。


阅读 157

收藏
2021-04-14

共1个答案

小编典典

您可以使用UNION子句非常简单地执行此操作:

Select Scan_ID, 'A' as Region, A_Volume as volume
    union all
Select Scan_ID, 'B' as Region, B_Volume as volume
    union all
Select Scan_ID, 'C' as Region, C_Volume as volume
2021-04-14