要件は、結果をピボット テーブル形式で再現することです。
毎月 22 個のテーブルがあり、各テーブルには約 150 万行あります。望ましい出力は、各製品/カテゴリの情報を保持する 22 のテーブルであり、列形式で製品化する必要があります。
11g ではピボット関数を使用して再生成し、10g では次のクエリを作成しました。このクエリは 1 日間実行され続け、結果は返されません。これは、最大集計関数の計算に膨大な時間がかかるためです。次のクエリを書き直す方法はありますか。
SELECT year,month,account_id,media_id,status,
max(CP1) AS CP,
max(CA1) AS CA,
max(CU1) AS CU,
max(GENDER1) AS GENDER,
max(AGE1) AS AGE,
max(AREA1) AS AREA,
max(SB1) AS SB,
max(SSP1) AS SSP,
max(SRP) AS scheme_redem_prpt,
max(BAL1) AS BAL,
max(PTS_RE1) AS PTS_RE,
max(PTS_EA1) AS PTS_EA,
max(dept_01_txn1) AS dept_01_txn,
max(dept_02_txn1) AS dept_02_txn,
max(dept_03_txn1) AS dept_03_txn,
max(dept_04_txn1) AS dept_04_txn,
max(dept_05_txn1) AS dept_05_txn,
max(dept_01_amt1) AS dept_01_amt,
max(dept_02_amt1) AS dept_02_amt,
max(dept_03_amt1) AS dept_03_amt,
max(dept_04_amt1) AS dept_04_amt,
max(dept_05_amt1) AS dept_05_amt
FROM (SELECT year,month,account_id,media_id,status,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('CR1') , prdatt_value, null),'00') AS CP1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('CR2') , prdatt_value, null),'00') AS CA1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('CR3') , prdatt_value, null),'00') AS CU1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('GENDER') , prdatt_value, null),'00') AS GENDER1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('AGE') , prdatt_value, null),'00') AS AGE1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('AREA') , prdatt_value, null),'00') AS AREA1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('SB1') , prdatt_value, null),'00') AS SB1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('SB2') , prdatt_value, null),'00') AS SSP1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('SB3') , prdatt_value, null),'00') AS SRP,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('SR1') , prdatt_value, null),'00') AS BAL1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('SR2') , prdatt_value, null),'00') AS PTS_RE1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('SR3') , prdatt_value, null),'00') AS PTS_EA1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_01_TXN') , prdatt_value, null),'00') AS dept_01_txn1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_02_TXN') , prdatt_value, null),'00') AS dept_02_txn1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_03_TXN') , prdatt_value, null),'00') AS dept_03_txn1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_04_TXN') , prdatt_value, null),'00') AS dept_04_txn1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_05_TXN'), prdatt_value, null),'00') AS dept_05_txn1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_01_AMT') , prdatt_value, null),'00') AS dept_01_amt1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_02_AMT') , prdatt_value, null),'00') AS dept_02_amt1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_03_AMT') , prdatt_value, null),'00') AS dept_03_amt1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_04_AMT') , prdatt_value, null),'00') AS dept_04_amt1,
nvl(decode(prdatt_id,util_pkg.fnc_get_Value('DEPT_05_AMT') , prdatt_value, null),'00') AS dept_05_amt1
FROM (
select year, month, account_id, media_id,prdatt_id, prdatt_iid, prdatt_value , status
from ac_prd_tab_01
union all
select year, month, account_id, media_id,prdatt_id, prdatt_iid, prdatt_value , status
from ac_prd_tab_02
union all
select year, month, account_id, media_id,prdatt_id, prdatt_iid, prdatt_value , status
from ac_prd_tab_03
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_04 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_05 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_06 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_07 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_08 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_09 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_10 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_11 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_12 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_13 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_14 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_15 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_16 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_17 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_18 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_19 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_20 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_21 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
union all
select a.year, a.month, a.account_id, b.media_id , a.prdatt_id, a.prdatt_iid, a.prdatt_value , a.status
from ac_prd_tab_22 a,
dtl_monthly b
where a.year= b.year and a.month=b.month and a.account_id=b.account_id
)
)
GROUP BY year,month,account_id, media_id,status
/