Home » SQL & PL/SQL » SQL & PL/SQL » Unpivot Query Help to transpose the data (Oracle 11g)
Unpivot Query Help to transpose the data [message #653725] |
Sat, 16 July 2016 12:15 |
|
arifs3738
Messages: 39 Registered: November 2015 Location: India
|
Member |
|
|
Input
C1 C2 C3 C4
A 1 2 3
B 4 5 6
Table Script:
CREATE TABLE A1
( C1 VARCHAR2(5),
C2 NUMBER,
C3 NUMBER,
C4 NUMBER
);
INSERT INTO A1 VALUES ('A',1,2,3);
INSERT INTO A1 VALUES ('B',4,5,6);
COMMIT;
I want below output...please help me in writing SQL query....
Output
|
|
|
Re: Unpivot Query Help to transpose the data [message #653726 is a reply to message #653725] |
Sat, 16 July 2016 12:44 |
|
Michel Cadot
Messages: 68665 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
SQL> with lines as (select level line from dual connect by level <= 4),
2 data as (select a1.*, row_number() over (order by c1) rn from a1)
3 select max(decode(rn, 1, decode(line, 1,c1, 2,c2, 3,c3, 4,c4))) c1,
4 max(decode(rn, 2, decode(line, 1,c1, 2,c2, 3,c3, 4,c4))) c2
5 from lines, data
6 group by line
7 order by line
8 /
C1 C2
----- -----
A B
1 4
2 5
3 6
4 rows selected.
|
|
|
|
Goto Forum:
Current Time: Fri Jun 28 09:37:55 CDT 2024
|