SQL:“反向”转置表格 [英] SQL: "Reverse" transpose a table

查看:111
本文介绍了SQL:“反向”转置表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下表显示了很多有关移置的问题...

I saw a lot of questions on transposing from the below table...

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



to this table.

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

但是,我需要做相反的事情,并且试图把我的头缠在这个问题上有麻烦。有人可以帮忙吗?

However, I need to do the inverse, and have trouble trying to wrap my head around this problem. Can anyone help?

谢谢。

推荐答案

您可以做到使用UNION子句非常简单:

You could do this very simply with a UNION clause:

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

这篇关于SQL:“反向”转置表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆