Home > database >  Oracle lines of columns
Oracle lines of columns

Time:09-20

Raw data:


Want to achieve results:



CodePudding user response:

Actually no one reply!

CodePudding user response:

A variety of methods are allowed,
Decode () the case when the two methods are all can

CodePudding user response:

 CREATE TABLE t (stage INTEGER, daily INTEGER, or an INTEGER, dayin INTEGER, dayout INTEGER, dayeff INTEGER); 
INSERT INTO t VALUES (1, 200, 1000, 80, 90, 150);
INSERT INTO t VALUES (2, 345, 2345, null, null, null);
INSERT INTO t VALUES (3, 1, 4, null, null, null);
INSERT INTO t VALUES (4, 50, 567, null, 34, null);
INSERT INTO t VALUES (5, 345, 34, 33, 234, 999);
INSERT INTO t VALUES (6, 658, 78, 66, 54, 200);
INSERT INTO t VALUES (9, 7, 88, 99, 33, 87);
INSERT INTO t VALUES (8, 90, 400, 55, 66, 77);

SELECT *
The FROM (SELECT 'target volume,' AS "process", stage, daily
The FROM t
)
The PIVOT (SUM (daily) FOR (stage) IN (1 AS "1", 2 AS "2", 3 AS "3", 4 AS "4", 5 AS "5", 6 AS "6", 7 AS "7", 8 AS "8"))
UNION ALL
SELECT *
The FROM (SELECT target quantity month, stage, or
The FROM t
)
PIVOT (SUM (or) FOR (stage) IN (1 AS "1", 2 AS "2", 3 AS "3", 4 AS "4", 5 AS "5", 6 AS "6", 7 AS "7", 8 AS "8"))
UNION ALL
SELECT *
The FROM (SELECT 'input on the same day, stage, dayin
The FROM t
)
The PIVOT (SUM (dayin) FOR (stage) IN (1 AS "1", 2 AS "2", 3 AS "3", 4 AS "4", 5 AS "5", 6 AS "6", 7 AS "7", 8 AS "8"))
UNION ALL
SELECT *
The FROM (SELECT 'on the day of the output stage, dayout
The FROM t
)
The PIVOT (SUM (dayout) FOR (stage) IN (1 AS "1", 2 AS "2", 3 AS "3", 4 AS "4", 5 AS "5", 6 AS "6", 7 AS "7", 8 AS "8"))
UNION ALL
SELECT *
The FROM (SELECT 'on the day of production efficiency, stage, dayeff
The FROM t
)
The PIVOT (SUM (dayeff) FOR (stage) IN (1 AS "1", 2 AS "2", 3 AS "3", 4 AS "4", 5 AS "5", 6 AS "6", 7 AS "7", 8 AS "8"))
;

Process | 1 | 2 | 3 | 4 5 6 7 | | | | | 8
-- -- -- -- -- - | -- - | -- - | -- - | -- - | -- - | -- - | -- - | -- - |
Target volume day | 200 | 345 | 1 | | 50 345 | 658 | | 90 | 88
Target quantity in 1000 | | 2345 | | 567 | | 34 78 | 99 | 400 |
Into the day | 80 | | | | | 66 | | 9 55 33 |
The output 90 | | | | 34 | | 234 | | 66 | 33 54
The production efficiency | 150 | | | | 999 | 200 | 87 | 77 |

CodePudding user response:

Privot () () (in... Also can),

CodePudding user response:

Pivot for () () (in... Also can),
  • Related