Hi Harshitha,
the NUSI on CUST_KEY will not be used for the join, only a NUPI on CUST_KEY, but this will probably skew your table and create other problems.
You might change that single aggregate to two steps:
SELECT 'UNKNOWN' , 'UNKNOWN' , 0 , - 999 ,
C.BR_PARTY_KEY ,
'UNKNOWN' ,SUM ( A.EX_QTY ) ,
SUM ( CAST( A.LIST_PRICE_AMT AS DOUBLE PRECISION ) ) ,
SUM ( CAST( A.NET_PRICE_AMT AS DOUBLE PRECISION ) ) ,
SUM ( CAST( A.COST_AMT AS DOUBLE PRECISION ) ) ,
'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'N' , 'UNKNOWN' ,
'N' , 'N' , 'N'
FROM
(
SELECT
CUST_KEY,
SUM ( A.EX_QTY ) AS EX_QTY,
SUM ( CAST( A.LIST_PRICE_AMT AS DOUBLE PRECISION ) ) AS LIST_PRICE_AMT,
SUM ( CAST( A.NET_PRICE_AMT AS DOUBLE PRECISION ) ) AS NET_PRICE_AMT,
SUM ( CAST( A.COST_AMT AS DOUBLE PRECISION ) ) AS COST_AMT
FROM ORDDB.BKGS A
WHERE a.ser_flag = 'N'
GROUP BY 1
) A,
REFDB.CUST_PARTY C
WHERE A.CUST_KEY = C.CUST_KEY
GROUP BY C.BR_PARTY_KEYThus you greatly reduce the number of rows before the join.
And i'd suggest changing the DOUBLE PRECISION to a DECIMAL, as DOUBLE is the same as FLOAT, limited to 15-16 significant digits, wheras DEC is up to 38 digits.
Dieter
↧