SELECT
YEAR
,MONTH
,WEEK
,A.customer_id
,C.CP_PK
,C.DEPT_PK ,decode (e.EN_TYPE,'11', e.EN_PK ) as COL1
,decode (e.EN_TYPE,'11', d2.ATTR_PK) as COL2
,decode (e.EN_TYPE,'10', e.EN_PK ) as COL3
,decode (e.EN_TYPE,'13', e.EN_PK ) as COL4
,DECODE (e.EN_TYPE,'13', d2.ATTR_PK) as COL5
,COUNT(*) TXN_COUNT
,SUM(A_AMOUNT) TOTAL_AMT
FROM TXN_HEADER T
,CUSTOMER A
,TXN_DETAIL D1
,TXN_DETAIL D2
,CP_ATTRIBUTE C
,GEN_LOOKUP e
WHERE A.TYPE = 0
AND T.CUSTOMER_ID = A.customer_id
AND T.TXN_PK= D1.TXN_PK
AND T.TXN_PK= D2.TXN_PK
AND D1.CP_PK = C.CP_PK
AND D1.OPERATION = 1
and e.en_code = d2.new_code
AND T.TXN_PK= 12313
GROUP BY
YEAR
,MONTH
,WEEK
,A.customer_id
,C.CP_PK
,C.DEPT_PK
,decode (e.EN_TYPE,'11', e.EN_PK )
,decode (e.EN_TYPE,'11', d2.ATTR_PK)
,decode (e.EN_TYPE,'10', e.EN_PK)
,decode (e.EN_TYPE,'13', e.EN_PK)
,DECODE (e.EN_TYPE,'13', d2.ATTR_PK)
生成される出力は次のとおりです
YEAR MONTH WEEK CUSTOMER ID CP_PK DEPT_PK COL1 COL2 COL3 COL4 COL5 TXN_COUNT TOTAL_AMT
2012 8 32 119 127 -1 74 61 1
2012 8 32 119 127 -1 73 63 1
2012 8 32 119 127 -1 67 1
2012 8 32 119 128 -1 73 63 1
2012 8 32 119 128 -1 74 61 1
2012 8 32 119 128 -1 67 1
ここでは、col1からcol5が散在しています。行にすべての値が必要です。
このような
YEAR MONTH WEEK CUSTOMER ID CP_PK DEPT_PK COL1 COL2 COL3 COL4 COL5 TXN_COUNT TOTAL_AMT
2012 8 32 119 127 -1 73 63 67 74 61 1
2012 8 32 119 128 -1 73 63 67 74 61 1