在unpivot查询

时间:2015-04-22 21:37:41

标签: tsql unpivot

我们有这个UNPIVOT查询。

SELECT Value
FROM (Your select statement) as x
UNPIVOT (Value FOR val IN (a, b, c, d)) as p 

产生如下结果:

Value
value1
value2
value3
value4

我们如何详细说明列名?

Value     ColumnName
value1    a
value2    b
value3    c
value4    d

1 个答案:

答案 0 :(得分:-2)

感谢Giorgi。将val添加到SELECT子句:

SELECT Value, val
FROM (Your select statement) as x
UNPIVOT (Value FOR val IN (a, b, c, d)) as p