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