OPERATIONNAMECODE |
MODELCODE2 |
MODELCODE |
SILJUK |
D_PLAN |
D_SILJUK |
3122 |
3.96GE |
GE |
100 |
0 |
0 |
3122 |
3.96GL |
GL |
200 |
0 |
0 |
3122 |
4.97GQ |
GQ |
300 |
0 |
0 |
3200 |
3.96GE |
GE |
400 |
0 |
0 |
3200 |
3.96GL |
GL |
500 |
0 |
0 |
3200 |
5.84HK |
HK |
900 |
0 |
0 |
3200 |
2.34CT |
CT |
750 |
0 |
0 |
3250 |
3.96GE |
GE |
580 |
0 |
0 |
3250 |
3.96GL |
GL |
690 |
0 |
0 |
3250 |
5.48HQ |
HQ |
770 |
0 |
0 |
3250 |
7.34HL |
HL |
290 |
0 |
0 |
3250 |
6.54TC |
TC |
334 |
0 |
0 |
3250 |
6.54TC |
TC |
334 |
0 |
0 |
3260 |
3.96GE |
GE |
223 |
0 |
0 |
3260 |
4.97GL |
GL |
436 |
0 |
0 |
1). 월기준코드(위)
OPERATIONNAMECODE |
MODELCODE2 |
MODELCODE |
SILJUK |
D_PLAN |
D_SILJUK |
3122 |
|
GE |
0 |
0 |
321 |
3200 |
|
GL |
0 |
0 |
532 |
3250 |
|
GE |
0 |
0 |
346 |
3260 |
|
GE |
0 |
0 |
876 |
2). 일기준코드(위)
OPERATIONNAMECODE |
MODELCODE2 |
MODELCODE |
SILJUK |
D_PLAN |
D_SILJUK |
3122 |
3.96GE |
GE |
100 |
0 |
321 |
3122 |
3.96GL |
GL |
200 |
0 |
0 |
3122 |
4.97GQ |
GQ |
300 |
0 |
0 |
3200 |
2.34CT |
CT |
750 |
0 |
0 |
3200 |
3.96GE |
GE |
400 |
0 |
0 |
3200 |
3.96GL |
GL |
500 |
0 |
532 |
3200 |
5.84HK |
HK |
900 |
0 |
0 |
3250 |
3.96GE |
GE |
580 |
0 |
346 |
3250 |
3.96GL |
GL |
690 |
0 |
0 |
3250 |
7.34HL |
HL |
290 |
0 |
0 |
3250 |
5.48HQ |
HQ |
770 |
0 |
0 |
3250 |
6.54TC |
TC |
668 |
0 |
0 |
3260 |
3.96GE |
GE |
223 |
0 |
876 |
3260 |
4.97GL |
GL |
436 |
0 |
0 |
3). OPERATIONNAMECODE 와 MODELCODE 기준 합침(위)
- D_PLAN(일 계획값) 은 코드테이블에서가져오기위해서 0으로 했음)
OPERATIONNAMECODE |
MODELCODE |
ATTR2 |
3122 |
GE |
2022 |
3200 |
GL |
3344 |
3250 |
GL |
4487 |
4). 코드테이블(위)
- ATTR2는 일계획값
OPERATIONNAMECODE |
MODELCODE2 |
MODELCODE |
SILJUK |
ATTR2 |
D_SILJUK |
3122 |
3.96GE |
GE |
100 |
2022 |
321 |
3122 |
3.96GL |
GL |
200 |
|
0 |
3122 |
4.97GQ |
GQ |
300 |
|
0 |
3200 |
2.34CT |
CT |
750 |
|
0 |
3200 |
3.96GE |
GE |
400 |
|
0 |
3200 |
3.96GL |
GL |
500 |
3344 |
532 |
3200 |
5.84HK |
HK |
900 |
|
0 |
3250 |
3.96GE |
GE |
580 |
|
346 |
3250 |
3.96GL |
GL |
690 |
4487 |
0 |
3250 |
5.48HQ |
HQ |
770 |
|
0 |
3250 |
6.54TC |
TC |
668 |
|
0 |
3250 |
7.34HL |
HL |
290 |
|
0 |
3260 |
3.96GE |
GE |
223 |
|
876 |
3260 |
4.97GL |
GL |
436 |
|
0 |
5) . 3) 과 4) 두테이블을 이용하여 3)에 D_PLAN(일계획값을 채워넣음) (위)
WITH T AS
(
SELECT OPERATIONNAMECODE, MAX(MODELCODE2) MODELCODE2, MODELCODE
, SUM(SILJUK) SILJUK
, SUM(D_PLAN) D_PLAN
, SUM(D_SILJUK) D_SILJUK
FROM
(
SELECT * FROM
(
SELECT '3122' OPERATIONNAMECODE, '3.96GE' MODELCODE2, 'GE' MODELCODE, 100 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3122' OPERATIONNAMECODE, '3.96GL' MODELCODE2, 'GL' MODELCODE, 200 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3122' OPERATIONNAMECODE, '4.97GQ' MODELCODE2, 'GQ' MODELCODE, 300 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3200' OPERATIONNAMECODE, '3.96GE' MODELCODE2, 'GE' MODELCODE, 400 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3200' OPERATIONNAMECODE, '3.96GL' MODELCODE2, 'GL' MODELCODE, 500 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3200' OPERATIONNAMECODE, '5.84HK' MODELCODE2, 'HK' MODELCODE, 900 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3200' OPERATIONNAMECODE, '2.34CT' MODELCODE2, 'CT' MODELCODE, 750 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3250' OPERATIONNAMECODE, '3.96GE' MODELCODE2, 'GE' MODELCODE, 580 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3250' OPERATIONNAMECODE, '3.96GL' MODELCODE2, 'GL' MODELCODE, 690 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3250' OPERATIONNAMECODE, '5.48HQ' MODELCODE2, 'HQ' MODELCODE, 770 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3250' OPERATIONNAMECODE, '7.34HL' MODELCODE2, 'HL' MODELCODE, 290 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3250' OPERATIONNAMECODE, '6.54TC' MODELCODE2, 'TC' MODELCODE, 334 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3250' OPERATIONNAMECODE, '6.54TC' MODELCODE2, 'TC' MODELCODE, 334 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3260' OPERATIONNAMECODE, '3.96GE' MODELCODE2, 'GE' MODELCODE, 223 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL UNION ALL
SELECT '3260' OPERATIONNAMECODE, '4.97GL' MODELCODE2, 'GL' MODELCODE, 436 SILJUK, 0 D_PLAN, 0 D_SILJUK FROM DUAL
)
UNION ALL
SELECT * FROM
(
SELECT '3122' OPERATIONNAMECODE, '' MODELCODE2, 'GE' MODELCODE, 0 SILJUK, 0 D_PLAN, 321 D_SILJUK FROM DUAL UNION ALL
SELECT '3200' OPERATIONNAMECODE, '' MODELCODE2, 'GL' MODELCODE, 0 SILJUK, 0 D_PLAN, 532 D_SILJUK FROM DUAL UNION ALL
SELECT '3250' OPERATIONNAMECODE, '' MODELCODE2, 'GE' MODELCODE, 0 SILJUK, 0 D_PLAN, 346 D_SILJUK FROM DUAL UNION ALL
SELECT '3260' OPERATIONNAMECODE, '' MODELCODE2, 'GE' MODELCODE, 0 SILJUK, 0 D_PLAN, 876 D_SILJUK FROM DUAL
)
)
GROUP BY OPERATIONNAMECODE, MODELCODE
ORDER BY OPERATIONNAMECODE, MODELCODE
)
SELECT T.OPERATIONNAMECODE, T.MODELCODE2, T.MODELCODE, T.SILJUK, S.ATTR2, T.D_SILJUK
FROM T, (
SELECT '3122' OPERATIONNAMECODE, 'GE' MODELCODE, 2022 ATTR2 FROM DUAL UNION ALL
SELECT '3200', 'GL', 3344 FROM DUAL UNION ALL
SELECT '3250', 'GL', 4487 FROM DUAL
)S
WHERE T.OPERATIONNAMECODE = S.OPERATIONNAMECODE(+)
AND T.MODELCODE = S.MODELCODE(+)
ORDER BY T.OPERATIONNAMECODE, MODELCODE2
좀더 쉽게할수없을까요? ;;