我有以下类型的表:
ID | Key | Value
-- --- -----
1 A aa
2 B bb
3 A ay
4 C cc
5 B bx
6 C ct
我需要输出:
A B C
--- --- ---
aa bb cc
ay bx ct
当我将 PIVOT 与子查询一起使用时,它不起作用:
Select * from (Select Key, Value, Id from tableName
pivot (max(Value) for Key IN (SELECT distinct Key from tableName)));
如果我使用 PIVOT xml,则子查询有效:
Select * from (Select Key, Value, Id from tableName)
pivot xml (max(Value) for Key IN (SELECT distinct Key from tableName));
但是当使用 PIVOT xml 时,我得到了 xml 形式的输出:
A B C
--- --- ---
<PivotSet><item...aa ... ...
如何在没有 xml 标签的情况下将其转换为表格输出?任何帮助将不胜感激。谢谢!