sum(case when f.drop_option_code ='D01' then f.referral_amount else null end) '14' /*D01首年渠道服务费*/,
sum(case when f.drop_option_code ='D01' then f.referral_amount else null end) '14' /*D01首年渠道服务费*/,
sum(case when f.drop_option_code ='D02' then f.referral_amount else null end) '15' /*D02续年渠道服务费*/,
sum(case when f.drop_option_code ='D02' then f.referral_amount else null end) '15' /*D02续年渠道服务费*/,
IF(f.rule_id is null, if(o.settlement_rule_type=1,'简单基本法','标准基本法'),
'特殊结算' as '16' /*基本法属性*/,
(select (case settlement_rule_type when 1 then '简单基本法' when 2 then '标准基本法' when 3 then '特殊结算' when 4 then if(o.settlement_rule_type=1,'简单基本法','标准基本法') end)
from ag_settlement_rule_base where id = f.rule_id
)
) '16' /*基本法属性*/,
sum(case when f.drop_option_code ='D91' then f.referral_amount else null end) as '17' /*D91渠道加扣款1*/,
sum(case when f.drop_option_code ='D91' then f.referral_amount else null end) as '17' /*D91渠道加扣款1*/,
sum(case when f.drop_option_code ='D92' then f.referral_amount else null end) as '18' /*D92渠道加扣款2*/,
sum(case when f.drop_option_code ='D92' then f.referral_amount else null end) as '18' /*D92渠道加扣款2*/,