select /*+index(ttjid IX_TB_TK_JISSEKI_DETAIL_06_FK)*/
ttbi.tk_np_sha_code AS tkNpShaNameRyaku,
‘2015/05‘ AS uriageNengetsu,
ttjid.uriage_bu_ka_code AS uriageBuKaCode,
ttjid.Gyosyu_MCode AS gyosyuMcode,
ttjid.adv_nushi_code AS advNushiCode,
ttjid.Gyosyu_SCode AS gyosyuScode,
(select tsar.Shukei_Group_Code
from tb_shukei_adv_relation tsar
where ttbi.adv_baitai_bunrui_code = tsar.adv_baitai_bunrui_code
AND tsar.shukei_group_code IN
(‘001010‘, ‘001020‘, ‘011010‘, ‘011020‘, ‘011030‘)
and rownum = 1) AS shukeiGroupCode,
ttbi.adv_baitai_bunrui_code AS advBaitaiBunruiCode,
ttbi.tk_np_sha_code AS tkNpShaCode,
ROUND(COALESCE(SUM(ttjid.kansan_dansu), 0) / 1000, 3) AS dansuSum
from TB_TK_BAITAI_INFO ttbi, TB_TK_JISSEKI_INFO_DETAIL ttjid
where ttbi.ksai_sha_code = SUBSTR(‘120‘, 1, 1)
AND ttbi.keisai_jisseki_mngr_num = ttjid.keisai_jisseki_mngr_num
AND ttbi.finish_state_code = ‘1‘
-- AND ttjid.del_flg = ‘0‘
AND ttjid.uriage_bu_ka_code = ‘120‘
AND ttjid.Gyosyu_MCode IN (‘20‘, ‘21‘, ‘22‘, ‘23‘, ‘24‘, ‘25‘, ‘26‘)
AND ttjid.Gyosyu_SCode IN
(‘10‘, ‘12‘, ‘13‘, ‘14‘, ‘16‘, ‘15‘, ‘19‘, ‘20‘, ‘18‘, ‘21‘, ‘23‘, ‘22‘, ‘25‘, ‘24‘, ‘27‘, ‘28‘, ‘26‘, ‘29‘)
AND ttbi.tk_np_sha_code IN (‘N003‘, ‘N004‘)
AND ttbi.del_flg = ‘0‘
AND to_char(ttbi.ksai_date, ‘YYYYMM‘) =
to_char(add_months(to_date(‘2015/05‘, ‘YYYY/MM‘), -12), ‘YYYYMM‘)
GROUP BY ttjid.uriage_bu_ka_code,
ttjid.Gyosyu_MCode,
ttjid.adv_nushi_code,
ttjid.Gyosyu_SCode,
ttbi.adv_baitai_bunrui_code,
ttbi.tk_np_sha_code
order by ttbi.tk_np_sha_code