我需要一些输入/帮助来转置表格:
Key | ATTR_NAME | ATTR_VALUE
1234| SS_VALUE | SENSITIVE
1234| XX_VALUE | 4456
转置后,我希望输出如下:
Key | SS_VALUE | XX_VALUE
1234| SENSITIVE| 4456
预先感谢
答案 0 :(得分:1)
如果这仅是2个cols转置,则条件聚合可能会帮助您-
SELECT Key
,MAX(CASE WHEN ATTR_NAME = 'SS_VALUE' THEN ATTR_VALUE END) SS_VALUE
,MAX(CASE WHEN ATTR_NAME = 'XX_VALUE' THEN ATTR_VALUE END) XX_VALUE
FROM T
GROUP BY Key
答案 1 :(得分:0)
一种选择是使用包含pivot
关键字的查询,因为您需要旋转:
select *
from
( select * from tab )
pivot
(
max(attr_value) for attr_name in ( 'SS_VALUE' as ss_value, 'XX_VALUE' as xx_value )
);