0

私が始めた場合:

SELECT * FROM unpivot_test;

         ID CUSTOMER_ID PRODUCT_CODE_A PRODUCT_CODE_B PRODUCT_CODE_C PRODUCT_CODE_D
 ---------- ----------- -------------- -------------- -------------- --------------
     1         101             10             20             30
     2         102             40                            50
     3         103             60             70             80             90
     4         104            100

ピボットを解除すると、値が取得されます

SELECT *
FROM   unpivot_test
UNPIVOT (quantity FOR product_code IN (product_code_a AS 'A', product_code_b AS 'B', product_code_c AS 'C', product_code_d AS 'D'));

        ID CUSTOMER_ID  P   QUANTITY
---------- ----------- --- ----------
     1         101     A         10
     1         101     B         20
     1         101     C         30
     2         102     A         40
     2         102     C         50
     3         103     A         60
     3         103     B         70
     3         103     C         80
     3         103     D         90
     4         104     A        100

数量列がP列の前に表示されるようにしたい場合はどうすればよいですか、基本的には

        ID CUSTOMER_ID   QUANTITY    P
---------- ----------- -----------  ----------
     1         101     10           A
     1         101     20           B

....。

Oracleのバージョンは11gです

4

1 に答える 1

2
SELECT ID, CUSTOMER_ID, QUANTITY, P FROM
(SELECT *
FROM   unpivot_test
UNPIVOT (quantity FOR product_code IN (product_code_a AS 'A', product_code_b AS 'B',  
product_code_c AS 'C', product_code_d AS 'D')));
于 2013-01-24T17:40:15.767 に答える