我正在尝试转动表格的PRODUCT列。具有两个单词的值之间有下划线:
某些PRODUCT值的EX:
PRODUCT
USSIC_Aviation
Avemco_Aviation
Property
Life
这是我的透视代码:
select SIMULATION, [USSIC Aviation], [Avemco Aviation], [Property], [Life]
from CM.CorrelationData
pivot
(
min(Value)
for replace(PRODUCT,'_',' ') in ([USSIC Aviation], [Avemco Aviation], [Property], [Life])
) piv
where Product_Description='UW'
它不喜欢replace(PRODUCT,'_',' ')
,但我不知道如何摆脱下划线。任何帮助将不胜感激!
答案 0 :(得分:0)
您无法在查询的PIVOT
区域中执行替换,因此您需要在子查询中执行它:
select SIMULATION, [USSIC Aviation], [Avemco Aviation], [Property], [Life]
from
(
select SIMULATION, replace(PRODUCT,'_',' ') Product, value
from CM.CorrelationData
where Product_Description='UW'
) d
pivot
(
min(Value)
for PRODUCT in ([USSIC Aviation], [Avemco Aviation], [Property], [Life])
) piv