안녕하세요... VIEW 생성중.. 어려움에 봉착하여 문의 남겨봅니다...
TABLE 1
bu |
period_date |
attribute1 |
attribute2 |
attribute3 |
attribute4 |
attribute5 |
biz_plan |
brake |
2019-09 |
korea |
PT |
A
|
H |
MBS |
140 |
brake |
2019-09 |
korea |
PT |
A |
K |
MBS |
100 |
brake |
2019-09 |
korea |
PT |
B |
M |
MBS |
100 |
brake |
2019-09 |
korea |
PT |
B |
E |
MBS |
100 |
brake |
2019-09 |
korea |
PT |
C |
A |
MBS |
150 |
brake |
2019-09 |
korea |
PT |
A |
H |
EBS |
40 |
brake |
2019-09 |
korea |
PT |
A |
K |
EBS |
250 |
brake |
2019-09 |
korea |
PT |
B |
M |
EBS |
40 |
brake |
2019-09 |
korea |
PT |
B |
E |
EBS |
120
|
brake |
2019-09 |
korea |
PT |
C |
A |
EBS |
140 |
TABLE2
bu |
period_date |
attribute1 |
attribute2 |
attribute3 |
attribute4 |
attribute5 |
current_plan |
brake |
2019-09 |
korea |
PT |
A
|
H |
MBS |
140 |
brake |
2019-09 |
korea |
PT |
A |
K |
MBS |
100 |
brake |
2019-09 |
korea |
PT |
B |
M |
MBS |
100 |
brake |
2019-09 |
korea |
PT |
B |
E |
MBS |
100 |
brake |
2019-09 |
korea |
PT |
C |
A |
MBS |
150 |
brake |
2019-09 |
korea |
PT |
A |
H |
EBS |
40 |
brake |
2019-09 |
korea |
PT |
A |
K |
EBS |
250 |
brake |
2019-09 |
korea |
PT |
B |
M |
EBS |
40 |
brake |
2019-09 |
korea |
PT |
B |
E |
EBS |
120 |
brake |
2019-09 |
korea |
PT |
C |
A |
EBS |
140 |
TABLE3
bu |
YEAR |
period_date |
attribute1 |
attribute2 |
attribute3 |
attribute4 |
attribute5 |
act_plan |
brake |
2019 |
2019-09 |
korea |
PT |
A
|
H |
MBS |
140 |
brake |
2019 |
2019-09 |
korea |
PT |
A |
K |
MBS |
100 |
brake |
2019 |
2019-09 |
korea |
PT |
B |
M |
MBS |
100 |
brake |
2019 |
2019-09 |
korea |
PT |
B |
E |
MBS |
100 |
brake |
2019 |
2019-09 |
korea |
PT |
C |
A |
MBS |
150 |
brake |
2019 |
2019-09 |
korea |
PT |
A |
H |
EBS |
40 |
brake |
2019 |
2019-09 |
korea |
PT |
A |
K |
EBS |
250 |
brake |
2019 |
2019-09 |
korea |
PT |
B |
M |
EBS |
40 |
brake |
2019 |
2019-09 |
korea |
PT |
B |
E |
EBS |
120 |
brake |
2019 |
2019-09 |
korea |
PT |
C |
A |
EBS |
140 |
3개 테이블을 이용해서 1년 년간 계획 데이터 및 누계데이터를 표현하는 통계 view를 만들려고합니다.
A1 |
A2 |
A3 |
A4 |
A5 |
BIZPLAN
(1~12월누적)
|
ACTUAL
(1~9월 누적)
|
progress
(actual/bizplan)
|
biz plan
(MBS+EBS)
|
current
(MBS+EBS)
|
actual
(MBS+EBS)
|
vs biz(%) |
vs current(%) |
biz plan
(MBS)
|
current
(MBS)
|
actual
(MBS)
|
biz plan
(EBS)
|
current
(EBS)
|
actual
(EBS)
|
brake |
korea |
PT |
A
|
H |
|
|
|
180 |
180 |
180 |
actual/bizplan |
actual/current |
140 |
140 |
140 |
40 |
40 |
40 |
brake |
korea |
PT |
A |
K |
|
|
|
350 |
350 |
350 |
|
|
100 |
100 |
100 |
250 |
250 |
250 |
|
|
|
소계 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
brake |
korea |
PT |
B |
M |
|
|
|
140 |
140 |
140 |
|
|
100 |
100 |
100 |
40 |
40 |
40 |
brake |
korea |
PT |
B |
E |
|
|
|
220 |
220 |
220 |
|
|
100 |
100 |
100 |
120 |
120 |
120 |
|
|
|
소계 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
brake |
korea |
PT |
C |
A |
|
|
|
290 |
290 |
290 |
|
|
150 |
150 |
150 |
140 |
140 |
140 |
|
|
|
소계 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TOTAL(총계) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
상기 표와 동일하게 3개 테이블을 이용하여 데이터를 만들고 싶습니다...
테이블 1,2,3 join 을 통해 현재 데이터가 9월만 있는데 앞쪽 데이터중 biz_Plan의 경우 1월 ~ 12월의 1년 예산이 입력되있고 actual의 경우 실제 1~9월 까지 데이터입니다.
조건절의 경우 A1, Period_date를 기준으로 조회하려 합니다
그리고 vs Current 뒤에 있는 MBS와 EBS의 경우 원데이터(attribute5의 값에 따라 유동적으로 변하는 부분입니다. MBS만 있는경우 MBS만 표기 등)
SELECT "YEAR","PERIOD_CODE","AFFILIATE","BU","ATTRIBUTE2","ATTRIBUTE3","ATTRIBUTE4","ATTRIBUTE5","BIZ_PLAN","CURRENT_PLAN","ACTUAL","VS_BIZ","VS_CURRENT","MBS_BIZ_PLAN","MBS_CURRENT_PLAN","MBS_ACTUAL","EBS_BIZ_PLAN","EBS_CURRENT_PLAN","EBS_ACTUAL" FROM
(SELECT YEAR,
PERIOD_CODE,
AFFILIATE,
BU,
ATTRIBUTE2,
ATTRIBUTE3,
ATTRIBUTE4,
ATTRIBUTE5,
(NVL(MBS_BIZ_PLAN, 0) + NVL(EBS_BIZ_PLAN, 0)) BIZ_PLAN,
(NVL(MBS_CURRENT_PLAN, 0) + NVL(EBS_CURRENT_PLAN, 0)) CURRENT_PLAN,
(NVL(MBS_ACTUAL, 0) + NVL(EBS_ACTUAL, 0)) ACTUAL,
((NVL(MBS_ACTUAL, 0) + NVL(EBS_ACTUAL, 0)) /
NULLIF((NVL(MBS_BIZ_PLAN, 0) + NVL(EBS_BIZ_PLAN, 0)), 0)) * 100 "VS_BIZ",
((NVL(MBS_ACTUAL, 0) + NVL(EBS_ACTUAL, 0)) /
NULLIF((NVL(MBS_CURRENT_PLAN, 0) + NVL(EBS_CURRENT_PLAN, 0)), 0)) * 100 "VS_CURRENT",
MBS_BIZ_PLAN,
MBS_CURRENT_PLAN,
MBS_ACTUAL,
EBS_BIZ_PLAN,
EBS_CURRENT_PLAN,
EBS_ACTUAL
FROM (SELECT MBS.YEAR,
MBS.PERIOD_CODE,
MBS.AFFILIATE,
MBS.BU,
MBS.ATTRIBUTE1,
EBS.ATTRIBUTE1,
MBS.ATTRIBUTE2,
MBS.ATTRIBUTE3,
MBS.ATTRIBUTE4,
MBS.ATTRIBUTE5,
MBS.BIZ_PLAN AS "MBS_BIZ_PLAN",
MBS.CURRENT_PLAN AS "MBS_CURRENT_PLAN",
MBS.ACTUAL AS "MBS_ACTUAL",
EBS.BIZ_PLAN AS "EBS_BIZ_PLAN",
EBS.CURRENT_PLAN AS "EBS_CURRENT_PLAN",
EBS.ACTUAL AS "EBS_ACTUAL"
FROM (SELECT *
FROM (SELECT BIZ.YEAR,
ACT.PERIOD_CODE,
ACT.AFFILIATE,
ACT.BU,
ACT.ATTRIBUTE1,
ACT.ATTRIBUTE2,
ACT.ATTRIBUTE3,
ACT.ATTRIBUTE4,
ACT.ATTRIBUTE5,
to_number(BIZ.ATTRIBUTE8) AS BIZ_PLAN,
NVL(to_number(ACT.ATTRIBUTE6), to_number(BIZ.ATTRIBUTE8)) AS CURRENT_PLAN,
to_number(RE.ATTRIBUTE6) AS ACTUAL
FROM (SELECT *
FROM XXCST_APL_CONS_EISBIS_UPLOAD
WHERE TEMPLATE_CODE = 'PC_SALES_BIZ_PLAN') BIZ,
(SELECT *
FROM XXCST_APL_CONS_EISBIS_UPLOAD
WHERE TEMPLATE_CODE = 'PC_SALES_ACT_PLAN') ACT,
(SELECT *
FROM XXCST_APL_CONS_EISBIS_UPLOAD
WHERE TEMPLATE_CODE = 'PC_SALES_RESULT') RE
WHERE BIZ.ATTRIBUTE1 = ACT.BU
AND ACT.BU = RE.BU
AND BIZ.ATTRIBUTE7 = ACT.PERIOD_CODE
AND ACT.PERIOD_CODE = RE.PERIOD_CODE
AND BIZ.ATTRIBUTE2 = ACT.ATTRIBUTE1
AND ACT.ATTRIBUTE1 = RE.ATTRIBUTE1
AND BIZ.ATTRIBUTE3 = ACT.ATTRIBUTE2
AND ACT.ATTRIBUTE2 = RE.ATTRIBUTE2
AND BIZ.ATTRIBUTE4 = ACT.ATTRIBUTE3
AND ACT.ATTRIBUTE3 = RE.ATTRIBUTE3
AND BIZ.ATTRIBUTE5 = ACT.ATTRIBUTE4
AND ACT.ATTRIBUTE4 = RE.ATTRIBUTE4
AND BIZ.ATTRIBUTE6 = ACT.ATTRIBUTE5
AND ACT.ATTRIBUTE5 = RE.ATTRIBUTE5
AND BIZ.ATTRIBUTE7 = ACT.PERIOD_CODE
AND ACT.PERIOD_CODE = RE.PERIOD_CODE)
WHERE ATTRIBUTE1 = 'MBS') MBS,
(SELECT *
FROM (SELECT BIZ.YEAR,
ACT.PERIOD_CODE,
ACT.AFFILIATE,
ACT.BU,
ACT.ATTRIBUTE1,
ACT.ATTRIBUTE2,
ACT.ATTRIBUTE3,
ACT.ATTRIBUTE4,
ACT.ATTRIBUTE5,
to_number(BIZ.ATTRIBUTE8) AS BIZ_PLAN,
NVL(to_number(ACT.ATTRIBUTE6), to_number(BIZ.ATTRIBUTE8)) AS CURRENT_PLAN,
to_number(RE.ATTRIBUTE6) AS ACTUAL
FROM (SELECT *
FROM XXCST_APL_CONS_EISBIS_UPLOAD
WHERE TEMPLATE_CODE = 'PC_SALES_BIZ_PLAN') BIZ,
(SELECT *
FROM XXCST_APL_CONS_EISBIS_UPLOAD
WHERE TEMPLATE_CODE = 'PC_SALES_ACT_PLAN') ACT,
(SELECT *
FROM XXCST_APL_CONS_EISBIS_UPLOAD
WHERE TEMPLATE_CODE = 'PC_SALES_RESULT') RE
WHERE BIZ.ATTRIBUTE1 = ACT.BU
AND ACT.BU = RE.BU
AND BIZ.ATTRIBUTE7 = ACT.PERIOD_CODE
AND ACT.PERIOD_CODE = RE.PERIOD_CODE
AND BIZ.ATTRIBUTE2 = ACT.ATTRIBUTE1
AND ACT.ATTRIBUTE1 = RE.ATTRIBUTE1
AND BIZ.ATTRIBUTE3 = ACT.ATTRIBUTE2
AND ACT.ATTRIBUTE2 = RE.ATTRIBUTE2
AND BIZ.ATTRIBUTE4 = ACT.ATTRIBUTE3
AND ACT.ATTRIBUTE3 = RE.ATTRIBUTE3
AND BIZ.ATTRIBUTE5 = ACT.ATTRIBUTE4
AND ACT.ATTRIBUTE4 = RE.ATTRIBUTE4
AND BIZ.ATTRIBUTE6 = ACT.ATTRIBUTE5
AND ACT.ATTRIBUTE5 = RE.ATTRIBUTE5
AND BIZ.ATTRIBUTE7 = ACT.PERIOD_CODE
AND ACT.PERIOD_CODE = RE.PERIOD_CODE)
WHERE ATTRIBUTE1 = 'EBS') EBS
WHERE MBS.YEAR = EBS.YEAR
AND MBS.PERIOD_CODE = EBS.PERIOD_CODE
AND MBS.AFFILIATE = EBS.AFFILIATE
AND MBS.BU = EBS.BU
AND MBS.ATTRIBUTE2 = EBS.ATTRIBUTE2
AND MBS.ATTRIBUTE3 = EBS.ATTRIBUTE3
AND MBS.ATTRIBUTE4 = EBS.ATTRIBUTE4
AND MBS.ATTRIBUTE5 = EBS.ATTRIBUTE5)) A1
테이블 정보가 조금 다르긴 하나... 현재 누적 데이터 부분을 제외하고 나머지 데이터가 출력되도록 view를 작성하긴하였는데
제가 짜놓은 쿼리의 경우 MBS, EBS 값이 고정되어 유동적이 변경이 어려 울 뿐만아니라.. 누적 데이터 산출에 어려움이 있습니다..
하여 다시 VIEW 생성을 해야 할것 같은데.. 상기 쿼리정도까지가 제수준인것같습니다...
이렇게 쓰고 보니 내용정리가 잘 안되있는것 같아 죄송합니다....
혹시나 해당 view에 대한 아이디어 있으신 분들은 의견 주시면 감사하겠습니다.... |