Использование UNPIVOT
для пар столбцов:
Установка Oracle :
CREATE TABLE table_name ( emi_id, work1, sal1, work2, sal2, work3, sal3, work4, sal4, work15, sal15 ) AS
SELECT 100, 'wiring', 1000, 'carpentry', 2000, 'painting', 3000, 'xyz', 4000, 'business', 15000 FROM DUAL
Запрос :
SELECT *
FROM table_name
UNPIVOT ( ( work, sal ) FOR key IN (
( work1, sal1 ) AS 1,
( work2, sal2 ) AS 2,
( work3, sal3 ) AS 3,
( work4, sal4 ) AS 4,
-- ...
( work15, sal15 ) AS 15
) )
Выход :
EMI_ID | KEY | WORK | SAL
-----: | --: | :-------- | ----:
100 | 1 | wiring | 1000
100 | 2 | carpentry | 2000
100 | 3 | painting | 3000
100 | 4 | xyz | 4000
100 | 15 | business | 15000
дБ <> скрипка здесь