By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
select * from V$VERSION;
BANNER | BANNER_FULL | BANNER_LEGACY | CON_ID |
---|---|---|---|
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release | Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release Version 23.2.0.0.0 |
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release | 0 |
CREATE TABLE t
(car VARCHAR2(10),month_1 VARCHAR2(10),amount_1 NUMBER,
month_2 VARCHAR2(10),amount_2 NUMBER);
INSERT INTO t (car, month_1, amount_1, month_2, amount_2) VALUES
('A', '202412', 100, '202501', 50),
('B', '202412', 200, '202501', 20),
('C', '202412', 300, '202501', 900);
3 rows affected
SELECT car,month,amount
FROM
(SELECT * FROM t)
UNPIVOT ( (month, amount)
FOR col IN ( (month_1, amount_1) as 1 ,(month_2, amount_2) as 2 )) ;
CAR | MONTH | AMOUNT |
---|---|---|
A | 202412 | 100 |
A | 202501 | 50 |
B | 202412 | 200 |
B | 202501 | 20 |
C | 202412 | 300 |
C | 202501 | 900 |