WITH elec_code AS
(
SELECT 1 no, '000' elec_cd FROM dual
UNION ALL SELECT 2, '110' FROM dual
UNION ALL SELECT 3, '140' FROM dual
UNION ALL SELECT 4, '170' FROM dual
UNION ALL SELECT 5, '185' FROM dual
UNION ALL SELECT 6, '200' FROM dual
UNION ALL SELECT 7, '237' FROM dual
UNION ALL SELECT 8, '245' FROM dual
UNION ALL SELECT 9, '255' FROM dual
UNION ALL SELECT 10, '265' FROM dual
UNION ALL SELECT 11, '275' FROM dual
)
SELECT DECODE(rn,1,card_bank_code) "카드사"
, DECODE(rn,1,'A',3,'B',5,'C') "구분1"
, DECODE(MOD(rn,2),1,'건수',0,'금액') "구분2"
, MIN(DECODE(no, 1,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "000"
, MIN(DECODE(no, 2,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "110"
, MIN(DECODE(no, 3,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "140"
, MIN(DECODE(no, 4,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "170"
, MIN(DECODE(no, 5,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "185"
, MIN(DECODE(no, 6,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "200"
, MIN(DECODE(no, 7,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "237"
, MIN(DECODE(no, 8,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "245"
, MIN(DECODE(no, 9,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "255"
, MIN(DECODE(no,10,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "265"
, MIN(DECODE(no,11,DECODE(rn,1,a_cnt,2,a_amt,3,b_cnt,4,b_amt,5,c_cnt,6,c_amt))) "275"
FROM (SELECT a.card_bank_code
, c.no
, c.elec_cd
, COUNT(CASE WHEN a.elec_cd = c.elec_cd AND a.mgr_org = c.elec_cd
THEN 1 END) a_cnt
, COUNT(CASE WHEN a.elec_cd != c.elec_cd AND a.mgr_org = c.elec_cd
THEN 1 END) b_cnt
, COUNT(CASE WHEN a.elec_cd = c.elec_cd AND a.mgr_org != c.elec_cd
THEN 1 END) c_cnt
, NVL(SUM(CASE WHEN a.elec_cd = c.elec_cd AND a.mgr_org = c.elec_cd
THEN amt END) , 0) a_amt
, NVL(SUM(CASE WHEN a.elec_cd != c.elec_cd AND a.mgr_org = c.elec_cd
THEN amt END) , 0) b_amt
, NVL(SUM(CASE WHEN a.elec_cd = c.elec_cd AND a.mgr_org != c.elec_cd
THEN amt END) , 0) c_amt
FROM (SELECT card_bank_code
, SUBSTR(elec_bill_num,1,3) elec_cd
, mgr_org
, COUNT(*) cnt
, SUM(card_settle_amt) amt
FROM card_man_tab
GROUP BY card_bank_code
, SUBSTR(elec_bill_num,1,3)
, mgr_org
) a
, elec_code c
GROUP BY a.card_bank_code
, c.no
, c.elec_cd
) aa
, (SELECT ROWNUM rn FROM dual CONNECT BY LEVEL <= 6) cc
GROUP BY aa.card_bank_code, cc.rn
ORDER BY aa.card_bank_code, cc.rn