要求是以数据透视表格式重新生成结果。
我们每个月有 22 个表,每个表大约有 150 万行。所需的输出是我们 22 个表,其中包含每个产品/类别的信息,并且需要以列格式进行产品
在 11g 中,我们使用 pivot 函数进行复制,在 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
/