"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
FROM tb_moko_kumi_item_info tmkii,
tb_shukei_adv_relation tsar
WHERE 1=1
]]>
AND to_char(tmkii.ksai_date, 'YYYY/MM') IN
#{item}
AND EXISTS
(SELECT 1
FROM
tb_moko_info_ksai_sha_betsu tmiksb,
tb_moko_info_matching tmim,
tb_moko_info_basic tmib
WHERE
tmib.receipt_num = tmiksb.receipt_num
AND tmib.his = tmiksb.his
AND ((tmib.yoyaku_waku_kubun_code IS NOT NULL AND
tmkii.receipt_num = tmib.yoyaku_waku_receipt_num) OR
(tmib.yoyaku_waku_kubun_code IS NULL AND
tmkii.receipt_num = tmib.receipt_num) OR
(tmkii.receipt_num = tmim.genko_umeawase_id AND
tmib.receipt_num = tmim.receipt_num AND
tmim.his= tmib.his ))
AND tmiksb.ksai_sha_code = tmkii.ksai_sha_code
AND tmiksb.jisseki_sign = tmkii.jisseki_sign
AND tmiksb.del_flg = '0'
AND tmib.moko_kubun_code <> '1'
AND tmib.moko_kind NOT IN ('12','19', '30')
AND tmib.yuko_sign = '2'
AND tmib.moko_state_code = '4'
AND tmib.karihan_sign = '0'
AND tmib.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmib.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmib.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tmib.del_flg = '0'
AND tmib.yuko_sign = '2')
AND (tmkii.han_keiretsu_code NOT IN
]]>
#{item.codeValue}
OR tmkii.han_keiretsu_code IS NULL)
AND tmkii.adv_baitai_bunrui_code = tsar.adv_baitai_bunrui_code
AND (CASE
WHEN EXISTS (SELECT 1
FROM tb_shukei_adv_relation tsar
WHERE tmkii.adv_kind_lcode = tsar.adv_kind_lcode
AND tmkii.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND tsar.count_flg = '1'
AND tsar.input_flg = '1') THEN
tmkii.adv_kind_lcode
ELSE
'*'
END) = tsar.adv_kind_lcode
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmkii.del_flg = '0')
WHERE r = 1),
innerView2 as (
SELECT/*+materialize*/kumi_item_mgmt_num,
shukei_group_code
FROM (
SELECT tmkii.kumi_item_mgmt_num, --申込組込時項目情報.申込組込時項目管理番号
tsar.shukei_group_code, --集計グループ広告媒体関連.集計グループコード
ROW_NUMBER() OVER(PARTITION BY tmkii.receipt_num, tmkii.ksai_sha_code ORDER BY tmkii.ksai_date ASC) r
FROM tb_moko_kumi_item_info tmkii,
tb_shukei_adv_relation tsar
WHERE 1=1
]]>
AND to_char(tmkii.ksai_date, 'YYYY/MM') IN
#{item}
AND EXISTS
(SELECT 1
FROM
tb_moko_info_ksai_sha_betsu tmiksb,
tb_moko_info_matching tmim,
tb_moko_info_basic tmib
WHERE
tmib.receipt_num = tmiksb.receipt_num
AND tmib.his = tmiksb.his
AND ((tmib.yoyaku_waku_kubun_code IS NOT NULL AND
tmkii.receipt_num = tmib.yoyaku_waku_receipt_num) OR
(tmib.yoyaku_waku_kubun_code IS NULL AND
tmkii.receipt_num = tmib.receipt_num) OR
(tmkii.receipt_num = tmim.genko_umeawase_id AND
tmim.receipt_num = tmib.receipt_num AND
tmim.his= tmib.his))
AND tmiksb.ksai_sha_code = tmkii.ksai_sha_code
AND tmiksb.jisseki_sign = tmkii.jisseki_sign
AND tmiksb.del_flg = '0'
AND tmib.moko_kubun_code <> '1'
AND tmib.yuko_sign = '2'
AND tmib.moko_state_code = '4'
AND tmib.moko_kind = '30'
AND tmib.karihan_sign = '0'
AND tmib.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmib.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmib.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tmib.del_flg = '0'
AND tmib.yuko_sign = '2'
)
AND (tmkii.han_keiretsu_code NOT IN
]]>
#{item.codeValue}
OR tmkii.han_keiretsu_code IS NULL)
AND tmkii.adv_baitai_bunrui_code = tsar.adv_baitai_bunrui_code
AND (CASE
WHEN EXISTS (SELECT 1
FROM tb_shukei_adv_relation tsar
WHERE tmkii.adv_kind_lcode = tsar.adv_kind_lcode
AND tmkii.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND tsar.count_flg = '1'
AND tsar.input_flg = '1') THEN
tmkii.adv_kind_lcode
ELSE
'*'
END) = tsar.adv_kind_lcode
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmkii.del_flg = '0')
WHERE r = 1)
select * from (SELECT shukeiGroupCode,
shukeiGroupName,
CASE
WHEN (mikomiFeeT IS NOT NULL OR mikomiFeeO IS NOT NULL OR
mikomiFeeS IS NOT NULL OR mikomiFeeN IS NOT NULL OR
mikomiFeeH IS NOT NULL) THEN
(nvl(mikomiFeeT,0)+nvl(mikomiFeeO,0)+nvl(mikomiFeeS,0)+nvl(mikomiFeeN,0)+nvl(mikomiFeeH,0))
ELSE
(mikomiFeeT+mikomiFeeO+mikomiFeeS+mikomiFeeN+mikomiFeeH)
END AS mikomiFeeSum,
mikomiFeeT as mikomiFeeT,
mikomiFeeO as mikomiFeeO,
mikomiFeeS as mikomiFeeS,
mikomiFeeN as mikomiFeeN,
mikomiFeeH as mikomiFeeH
FROM (
SELECT shukeiGroupCode AS shukeiGroupCode,
shukeiGroupName AS shukeiGroupName,
sum(T) AS mikomiFeeT,
sum(O) AS mikomiFeeO,
sum(S) AS mikomiFeeS,
sum(N) AS mikomiFeeN,
sum(H) AS mikomiFeeH
FROM (SELECT shukeiGroupCode,
shukeiGroupName,
CASE
WHEN ksaiShaCode = '1' THEN
netFee
END AS T,
CASE
WHEN ksaiShaCode = '2' THEN
netFee
END AS O,
CASE
WHEN ksaiShaCode = '3' THEN
netFee
END AS S,
CASE
WHEN ksaiShaCode = '4' THEN
netFee
END AS N,
CASE
WHEN ksaiShaCode = '5' THEN
netFee
END AS H
FROM (SELECT shukeiGroupCode,
shukeiGroupName,
ksaiShaCode,
SUM(netFee) AS netFee
FROM (
--405a
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_basic tmib,
tb_fee_info_basic tfib,
tb_moko_kumi_item_info tmkii,
tb_shukei_group tsg,
innerView
WHERE tmib.receipt_num = tfib.receipt_num
AND tmib.his = tfib.his
AND tmkii.ksai_sha_code = tfib.ksai_sha_code
AND innerView.shukei_group_code = tsg.shukei_group_code
AND tmkii.kumi_item_mgmt_num = innerView.kumi_item_mgmt_num
AND ((tmib.yoyaku_waku_kubun_code IN ('1','3','5') AND
tmkii.receipt_num =
tmib.yoyaku_waku_receipt_num) OR
(tmib.yoyaku_waku_kubun_code IS NULL AND
tmkii.receipt_num = tmib.receipt_num))
AND to_char(tmkii.ksai_date, 'YYYY/MM') = '2014/06' --遷移元画面.売上年月
AND tmib.moko_kubun_code <> '1'
AND tmib.moko_kind NOT IN ('12','19', '30')
AND tmib.yuko_sign = '2'
AND tmib.moko_state_code = '4'
AND tmib.karihan_sign = '0'
AND tmib.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmib.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmib.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tmkii.del_flg = '0'
AND tmib.del_flg = '0'
AND tfib.yuko_sign = '2'
AND tfib.del_flg = '0'
AND tsg.del_flg = '0'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--405a--原稿MATCHING
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_basic tmib,
tb_fee_info_basic tfib,
tb_moko_kumi_item_info tmkii,
tb_shukei_group tsg,
innerView
WHERE tmib.receipt_num = tfib.receipt_num
AND tmib.his = tfib.his
AND tmkii.ksai_sha_code = tfib.ksai_sha_code
AND innerView.shukei_group_code =
tsg.shukei_group_code
AND tmkii.kumi_item_mgmt_num =
innerView.kumi_item_mgmt_num
AND EXISTS
(SELECT 1
FROM tb_moko_info_matching tmim
WHERE tmkii.receipt_num =
tmim.genko_umeawase_id
AND tmim.receipt_num =
tmib.receipt_num
AND tmim.his= tmib.his)
AND tmib.yuko_sign = '2'
AND tmib.moko_state_code = '4'
AND tmib.moko_kubun_code <> '1'
AND tmib.moko_kind NOT IN ('12','19', '30')
AND tmib.karihan_sign = '0'
AND to_char(tmkii.ksai_date, 'YYYY/MM') = '2014/06' --遷移元画面.売上年月
AND tmib.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmib.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmib.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tmib.del_flg = '0'
AND tfib.del_flg = '0'
AND tmkii.del_flg = '0'
AND tsg.del_flg = '0'
AND tfib.yuko_sign = '2'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--405b
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_basic tmib,
tb_fee_info_basic tfib,
tb_moko_kumi_item_info tmkii,
tb_shukei_group tsg,
innerView2
WHERE
tmkii.kumi_item_mgmt_num =
innerView2.kumi_item_mgmt_num
AND tmib.receipt_num = tfib.receipt_num
AND tmib.his = tfib.his
AND tmkii.ksai_sha_code = tfib.ksai_sha_code
AND innerView2.shukei_group_code =
tsg.shukei_group_code
AND ((tmib.yoyaku_waku_kubun_code IN ('1','3','5') AND
tmkii.receipt_num =
tmib.yoyaku_waku_receipt_num) OR
(tmib.yoyaku_waku_kubun_code IS NULL AND
tmkii.receipt_num = tmib.receipt_num))
AND tmib.moko_kubun_code <> '1'
AND tmib.yuko_sign = '2'
AND tmib.moko_state_code = '4'
AND tmib.moko_kind = '30'
AND tmib.karihan_sign = '0'
AND to_char(tmkii.ksai_date, 'YYYY/MM') = '2014/06' --遷移元画面.売上年月
AND tmib.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmib.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmib.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmib.del_flg = '0'
AND tfib.del_flg = '0'
AND tmkii.del_flg = '0'
AND tsg.del_flg = '0'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--405b--原稿MATCHING
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_basic tmib,
tb_fee_info_basic tfib,
tb_moko_kumi_item_info tmkii,
tb_shukei_group tsg,
innerView2
WHERE tmib.receipt_num = tfib.receipt_num
AND tmib.his = tfib.his
AND tmkii.ksai_sha_code = tfib.ksai_sha_code
AND innerView2.shukei_group_code =
tsg.shukei_group_code
AND tmkii.kumi_item_mgmt_num =
innerView2.kumi_item_mgmt_num
AND EXISTS
(SELECT 1
FROM tb_moko_info_matching tmim
WHERE tmkii.receipt_num =
tmim.genko_umeawase_id
AND tmim.receipt_num =
tmib.receipt_num
AND tmim.his= tmib.his)
AND tmib.moko_kubun_code <> '1'
AND tmib.yuko_sign = '2'
AND tmib.moko_state_code = '4'
AND tmib.moko_kind = '30'
AND tmib.karihan_sign = '0'
AND to_char(tmkii.ksai_date, 'YYYY/MM') = '2014/06' --遷移元画面.売上年月
AND tmib.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmib.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmib.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmib.del_flg = '0'
AND tfib.del_flg = '0'
AND tmkii.del_flg = '0'
AND tsg.del_flg = '0'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--405c
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_basic tmib, --申込情報(基本)
tb_moko_info_ksai_sha_betsu tmiksb, --申込情報(掲載社別)
tb_fee_info_basic tfib, --料金情報(基本)
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg --集計グループ
WHERE
tmib.receipt_num = tmiksb.receipt_num
AND tmib.his = tmiksb.his
AND tmiksb.receipt_num = tfib.receipt_num
AND tmiksb.his = tfib.his
AND tmiksb.ksai_sha_code = tfib.ksai_sha_code
AND tsar.shukei_group_code = tsg.shukei_group_code
AND tmib.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND (tmib.adv_kind_lcode = tsar.adv_kind_lcode OR
tsar.adv_kind_lcode = '*')
AND ((to_char(tmib.ksai_kibo_start_date_time_t, 'YYYY/MM') = '2014/06' AND tmiksb.ksai_sha_code ='1') OR
(to_char(tmib.ksai_kibo_start_date_time_o, 'YYYY/MM') = '2014/06' AND tmiksb.ksai_sha_code ='2') OR
(to_char(tmib.ksai_kibo_start_date_time_s, 'YYYY/MM') = '2014/06' AND tmiksb.ksai_sha_code ='3') OR
(to_char(tmib.ksai_kibo_start_date_time_n, 'YYYY/MM') = '2014/06' AND tmiksb.ksai_sha_code ='4') OR
(to_char(tmib.ksai_kibo_start_date_time_h, 'YYYY/MM') = '2014/06' AND tmiksb.ksai_sha_code ='5') )
AND tmib.moko_kubun_code <> '1'
AND tmib.moko_kind not in ('12','19')
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmib.yuko_sign = '2'
AND tmib.moko_state_code = '4'
AND tmib.karihan_sign = '0'
AND tmib.kumikomi_fuyo_sign <> '0'
AND tmib.yoyaku_waku_kubun_code IS NULL
AND tmib.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmib.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmib.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmib.del_flg = '0'
AND tmiksb.del_flg = '0'
AND tfib.del_flg = '0'
AND tsar.del_flg = '0'
AND tsg.del_flg = '0'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--405d
SELECT ksaiShaCode,
shukeiGroupCode,
shukeiGroupName,
SUM(netFee) AS netFee
FROM (
--申込情報(汎用・基本)[受付番号,履歴番号] IN 申込情報(掲載社別) の場合
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_hanyou tmih, --申込情報(汎用・基本)
tb_fee_info_basic tfib, --料金情報(基本)
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg, --集計グループ
tb_moko_info_ksai_sha_betsu tmiksb --申込情報(掲載社別)
WHERE
tmih.receipt_num = tfib.receipt_num
AND tmih.his = tfib.his
AND tsar.shukei_group_code =
tsg.shukei_group_code
AND tmih.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND (tmih.adv_kind_lcode =
tsar.adv_kind_lcode OR
tsar.adv_kind_lcode = '*')
AND tmih.receipt_num = tmiksb.receipt_num
AND tmih.his = tmiksb.his
AND tmiksb.ksai_sha_code = tfib.ksai_sha_code
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmih.yuko_sign = '2'
AND tmih.moko_state_code = '4'
AND tmih.moko_kubun_code <> '1'
AND to_char(tmiksb.ksai_kibo_start_date_time, 'YYYY/MM') =
'2014/06' --遷移元画面.売上年月
AND tmih.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmih.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmih.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmih.del_flg = '0'
AND tfib.del_flg = '0'
AND tsar.del_flg = '0'
AND tmiksb.del_flg = '0'
and tsg.del_flg='0'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--申込情報(汎用・基本)[受付番号,履歴番号] IN 申込情報(サブメディア) の場合
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_hanyou tmih, --申込情報(汎用・基本)
tb_fee_info_basic tfib, --料金情報(基本)
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg, --集計グループ
tb_moko_info_sub_m_detail tmismd --申込情報(サブメディア地域・見本紙別)
WHERE
tmih.receipt_num = tfib.receipt_num
AND tmih.his = tmih.his
AND tsar.shukei_group_code =
tsg.shukei_group_code
AND tmih.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND (tmih.adv_kind_lcode =
tsar.adv_kind_lcode OR
tsar.adv_kind_lcode = '*')
AND tmih.receipt_num =
tmismd.receipt_num
AND tmih.his = tmismd.his
AND (tmismd.mihonshi_sign = '0' AND
tmismd.ksai_sha_code = tfib.ksai_sha_code
AND to_char(tmismd.hakou_date, 'YYYY/MM') = '2014/06' --遷移元画面.売上年月
)
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmih.yuko_sign = '2'
AND tmih.moko_state_code = '4'
AND tmih.moko_kubun_code <> '1'
AND tmih.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmih.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmih.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmih.del_flg = '0'
AND tfib.del_flg = '0'
AND tsar.del_flg = '0'
AND tmismd.del_flg = '0'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--申込情報(汎用・基本)[受付番号,履歴番号] IN 申込情報(サブメディア) の場合
SELECT tmih.uriage_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_hanyou tmih, --申込情報(汎用・基本)
tb_fee_info_basic tfib, --料金情報(基本)
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg --集計グループ
WHERE tmih.receipt_num = tfib.receipt_num
AND tmih.his = tmih.his
AND tsar.shukei_group_code =
tsg.shukei_group_code
AND tmih.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND (tmih.adv_kind_lcode =
tsar.adv_kind_lcode OR
tsar.adv_kind_lcode = '*')
AND tfib.ksai_sha_code IS NULL
AND ((EXISTS (SELECT 1
FROM tb_fee_info_basic t,
tb_moko_info_sub_m_detail t1
WHERE t.receipt_num = tmih.receipt_num
AND t.his = tmih.his
AND t1.receipt_num = tmih.receipt_num
AND t1.his = tmih.his
AND t1.mihonshi_sign = '1'
AND t1.ksai_sha_code IN ('1', '2', '3', '4')
AND t.yuko_sign = '2'
AND t.del_flg = '0'
AND t1.del_flg = '0'
AND t.ksai_sha_code = tmih.uriage_sha_code)))
AND EXISTS (SELECT 1
FROM tb_fee_info_basic t,
tb_moko_info_sub_m_detail t1
WHERE t.receipt_num = tmih.receipt_num
AND t.his = tmih.his
AND t1.receipt_num = tmih.receipt_num
AND t1.his = tmih.his
AND t1.mihonshi_sign = '0'
AND t1.ksai_sha_code = t.ksai_sha_code
AND to_char(t1.hakou_date, 'YYYY/MM') = '2014/06')
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmih.yuko_sign = '2'
AND tmih.moko_state_code = '4'
AND tmih.moko_kubun_code <> '1'
AND tmih.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmih.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmih.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmih.del_flg = '0'
AND tfib.del_flg = '0'
AND tsar.del_flg = '0'
GROUP BY tmih.uriage_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--申込情報(汎用・基本)[受付番号,履歴番号] IN 申込情報(サブメディア) の場合
SELECT ksaiShaCode,
shukeiGroupCode,
shukeiGroupName,
SUM(netFee) AS netFee
FROM (
SELECT tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
(SELECT MIN(t.ksai_sha_code)
FROM tb_fee_info_basic t
WHERE t.receipt_num = tmih.receipt_num
AND t.his = tmih.his
AND t.yuko_sign = '2') AS ksaiShaCode,
tfib.net_fee AS netFee
FROM tb_moko_info_hanyou tmih, --申込情報(汎用・基本)
tb_fee_info_basic tfib, --料金情報(基本)
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg --集計グループ
WHERE tmih.receipt_num = tfib.receipt_num
AND tmih.his = tmih.his
AND tsar.shukei_group_code =
tsg.shukei_group_code
AND tmih.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND (tmih.adv_kind_lcode =
tsar.adv_kind_lcode OR
tsar.adv_kind_lcode = '*')
AND tfib.ksai_sha_code IS NULL
AND ((NOT EXISTS
(SELECT 1
FROM tb_fee_info_basic t,
tb_moko_info_sub_m_detail t1
WHERE t.receipt_num = tmih.receipt_num
AND t.his = tmih.his
AND t1.receipt_num = tmih.receipt_num
AND t1.his = tmih.his
AND t1.del_flg = '0'
AND t1.receipt_num = tmih.receipt_num
AND t1.his = tmih.his
AND t1.mihonshi_sign = '1'
AND t1.ksai_sha_code IN ('1', '2', '3', '4')
AND t.yuko_sign = '2'
AND t.del_flg = '0'
AND t1.del_flg = '0'
AND t.ksai_sha_code = tmih.uriage_sha_code)))
AND EXISTS (SELECT 1
FROM tb_fee_info_basic t,
tb_moko_info_sub_m_detail t1
WHERE t.receipt_num = tmih.receipt_num
AND t.his = tmih.his
AND t1.receipt_num = tmih.receipt_num
AND t1.his = tmih.his
AND t1.mihonshi_sign = '0'
AND t1.ksai_sha_code = t.ksai_sha_code
AND to_char(t1.hakou_date, 'YYYY/MM') = '2014/06')
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmih.yuko_sign = '2'
AND tmih.moko_state_code = '4'
AND tmih.moko_kubun_code <> '1'
AND tmih.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmih.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmih.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmih.del_flg = '0'
AND tfib.del_flg = '0'
AND tsar.del_flg = '0'
)GROUP BY ksaiShaCode,
shukeiGroupCode,
shukeiGroupName
UNION ALL
--申込情報(汎用・基本)[受付番号,履歴番号] IN 申込情報(英文メディア) の場合
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_hanyou tmih, --申込情報(汎用・基本)
tb_fee_info_basic tfib, --料金情報(基本)
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg, --集計グループ
tb_moko_info_eibun_media tmiem --申込情報(英文メディア)
WHERE tmih.receipt_num = tfib.receipt_num
AND tmih.his = tfib.his
AND tsar.shukei_group_code =
tsg.shukei_group_code
AND tmih.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND (tmih.adv_kind_lcode =
tsar.adv_kind_lcode OR
tsar.adv_kind_lcode = '*')
AND tmih.receipt_num = tmiem.receipt_num
AND tmih.his = tmiem.his
AND to_char(tmiem.ksai_date, 'YYYY/MM') =
'2014/06' --遷移元画面.売上年月
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmih.yuko_sign = '2'
AND tmih.moko_state_code = '4'
AND tmih.moko_kubun_code <> '1'
AND tmih.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmih.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmih.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmih.del_flg = '0'
AND tfib.del_flg = '0'
AND tsar.del_flg = '0'
AND tmiem.del_flg = '0'
AND tsg.del_flg='0'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--申込情報(汎用・基本)[受付番号,履歴番号] IN 申込情報(デジタルメディア) の場合
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_hanyou tmih, --申込情報(汎用・基本)
tb_fee_info_basic tfib, --料金情報(基本)
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg, --集計グループ
tb_moko_info_digital_media tmidm --申込情報(デジタルメディア)
WHERE tmih.receipt_num = tfib.receipt_num
AND tmih.his = tfib.his
AND tsar.shukei_group_code =
tsg.shukei_group_code
AND tmih.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND (tmih.adv_kind_lcode =
tsar.adv_kind_lcode OR
tsar.adv_kind_lcode = '*')
AND tmih.receipt_num = tmidm.receipt_num
AND tmih.his = tmidm.his
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmih.yuko_sign = '2'
AND tmih.moko_state_code = '4'
AND tmih.moko_kubun_code <> '1'
AND tmih.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmih.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmih.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND to_char(tmidm.ksai_kikan_start_date, 'YYYY/MM') =
'2014/06' --遷移元画面.売上年月
AND tmih.del_flg = '0'
AND tfib.del_flg = '0'
AND tsar.del_flg = '0'
AND tmidm.del_flg = '0'
AND tsg.del_flg='0'
AND tfib.yuko_sign = '2'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--申込情報(汎用・基本)[受付番号,履歴番号]→申込情報(事業) の場合
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_moko_info_hanyou tmih, --申込情報(汎用・基本)
tb_fee_info_basic tfib, --料金情報(基本)
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg, --集計グループ
tb_moko_info_jigyo tmij --申込情報(事業)
WHERE tmih.receipt_num = tfib.receipt_num
AND tmih.his = tfib.his
AND tsar.shukei_group_code =
tsg.shukei_group_code
AND tmih.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND (tmih.adv_kind_lcode =
tsar.adv_kind_lcode OR
tsar.adv_kind_lcode = '*')
AND tmih.receipt_num = tmij.receipt_num
AND tmih.his = tmij.his
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmih.yuko_sign = '2'
AND tmih.moko_state_code = '4'
AND tmih.moko_kubun_code <> '1'
AND to_char(tmij.uriage_date, 'YYYY/MM') =
'2014/06' --遷移元画面.売上年月
AND tmih.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmih.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmih.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tfib.yuko_sign = '2'
AND tmih.del_flg = '0'
AND tfib.del_flg = '0'
AND tsar.del_flg = '0'
AND tmij.del_flg = '0'
AND tsg.del_flg='0'
GROUP BY tfib.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
)
GROUP BY shukeiGroupCode,
shukeiGroupName,
ksaiShaCode
UNION ALL
--405e
SELECT tmik.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tmik.net_fee) AS netFee
FROM tb_moko_info_keihi tmik, --経費情報
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg --集計グループ
WHERE tsar.shukei_group_code = tsg.shukei_group_code
AND tmik.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND tsar.adv_kind_lcode = '*'
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND tmik.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tmik.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tmik.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tmik.yuko_sign = '2'
AND tmik.moko_kubun_code <> '1'
AND tmik.keihi_moko_state_code = '4'
AND to_char(tmik.ksai_date, 'YYYY/MM') = '2014/06' --遷移元画面.売上年月
AND tmik.del_flg = '0'
AND tsar.del_flg = '0'
AND tsg.del_flg = '0'
GROUP BY tmik.ksai_sha_code,
tsg.shukei_group_code,
tsg.shukei_group_name
UNION ALL
--405g
SELECT tfib.ksai_sha_code AS ksaiShaCode,
tsg.shukei_group_code AS shukeiGroupCode,
tsg.shukei_group_name AS shukeiGroupName,
SUM(tfib.net_fee) AS netFee
FROM tb_annai_fee_info_basic tafib, --案内申込料金情報(基本)
tb_annai_fee_info_detail tafid, --案内申込料金情報(明細)
tb_fee_info_basic tfib, --料金情報(基本)
tb_annainaka_fee taf, --案内・案内中料金
tb_gyosyu_sbunrui tgs, --業種小分類
tb_shukei_adv_relation tsar, --集計グループ広告媒体関連
tb_shukei_group tsg --集計グループ
WHERE tafib.annai_fee_mgmt_num =
tafid.annai_fee_mgmt_num
AND tafid.receipt_num = tfib.receipt_num
AND tafid.his = tfib.his
AND tafid.annainaka_fee_num = taf.annainaka_fee_num
AND tafid.annainaka_fee_his = taf.annainaka_fee_his
AND taf.gyosyu_scode = tgs.gyosyu_scode
AND tafib.adv_baitai_bunrui_code =
tsar.adv_baitai_bunrui_code
AND tsar.adv_kind_lcode = '*'
AND tgs.apply_start_date <= tafib.ksai_date
AND tgs.apply_end_date >= tafib.ksai_date
AND tsar.shukei_group_code = tsg.shukei_group_code
AND tsar.count_flg = '1'
AND tsar.input_flg = '1'
AND to_char(tafib.ksai_date, 'YYYY/MM') = '2014/06' --遷移元画面.売上年月
AND tgs.gyosyu_mcode = '10' --遷移元画面.業種中分類コード
AND tafib.uriage_sha_code = '1' --遷移元画面.売上社コード
AND tafib.uriage_bu_ka_code = '110' --遷移元画面.担当部課コード
AND tafid.yuko_sign = '2'
AND tafid.moko_kubun_code <> '1'
AND tafid.moko_state_code = '4'
AND tfib.yuko_sign = '2'
AND tafib.del_flg = '0'
AND tafid.del_flg = '0'
AND tfib.del_flg = '0'
AND taf.del_flg = '0'
--and tgs.state_code = '20' --TODO 式样书中未写
AND tsar.del_flg = '0'
AND tsg.del_flg = '0'
GROUP BY tsg.shukei_group_code,
tsg.shukei_group_name,
tfib.ksai_sha_code)
GROUP BY shukeiGroupCode,
shukeiGroupName,
ksaiShaCode)
GROUP BY shukeiGroupCode,
shukeiGroupName,
ksaiShaCode,
netFee)
GROUP BY shukeiGroupCode,
shukeiGroupName))tempa
inner join TB_Shukei_Group tempb
on(tempa.shukeiGroupCode=tempb.Shukei_Group_Code)
order by tempb.Dsp_Jyun
]]>
Parameters: 2014/06(String), 2014/05(String), 2014/07(String), 1(String), 110(String), 10(String), T2(String), T3(String), 2014/06(String), 2014/05(String), 2014/07(String), 1(String), 110(String), 10(String), T2(String), T3(String), 2014/06(String), 1(String), 110(String), 10(String), 2014/06(String), 1(String), 110(String), 10(String), 2014/06(String), 1(String), 110(String), 10(String), 20