【发布时间】:2017-01-30 12:24:21
【问题描述】:
我是 sql 语言的新手,需要一些帮助来重新排列数据。
(我正在使用 sql server 2008)
我有这张桌子(替代):
位号 |替换escr |替代代码 37664 | EANCUTIE3 | 14902778788926 37664 | EAN1 | 4902778788929 37664 | EANCUTIE1 | 4902778931653 37664 | EANCUTIE2 | 4902778931738我希望选择看起来像这样:
iteid EAN1 EANCUTIE1 EANCUTIE2 EANCUTIE3 37664 14902778788926 37664 4902778788929 37664 4902778931653 37664 4902778931738我尝试使用枢轴:
select *
from (
select iteid as [ID], substitutedescr as [descr], substitutecode as [Values]
from substitute) as s
PIVOT
(
SUM(SUBSTITUTECODE)
FOR [DESCR] in ( ean1, ean2, ean3, eancutie1, eancutie2, eancutie3)
) as pvt
但似乎我需要将兼容性级别设置为更高的值才能激活枢轴功能。
我有其他选择来获得这个结果吗?
谢谢。
【问题讨论】:
标签: sql-server pivot