oracle PIVOT

WITH CTE AS (
SELECT 'A' AS TAG,'NUM_1' AS ITEM,10 AS VAL FROM dual
UNION ALL
SELECT 'A','NUM_2',9 FROM dual
UNION ALL
SELECT 'A','NUM_3',8 FROM dual
UNION ALL
SELECT 'A','NUM_4',7 FROM dual
UNION ALL
SELECT 'B','NUM_1',22 FROM dual
UNION ALL
SELECT 'B','NUM_2',23 FROM dual
UNION ALL
SELECT 'B','NUM_4',24 FROM dual
UNION ALL
SELECT 'B','NUM_5',0 FROM dual
)
SELECT TAG,"'NUM_1'","'NUM_2'","'NUM_3'"
FROM CTE
PIVOT(
MAX(VAL) FOR ITEM IN ('NUM_1','NUM_2','NUM_3','NUM_4','NUM_5')
) t
ORDER BY TAG DESC

posted @ 2023-12-25 16:51  踏叶乘风  阅读(18)  评论(0编辑  收藏  举报