You are on page 1of 2

/*Period 01/07/2012 to 31/05/2015

01/06/2015 to 14/11/2015
15/11/2015 to 31/05/2016
01/06/2016 to till date
Format of Summary

No of Pol / Prem coll


Condition 1 Date of Commencement >= 01/01/2014
Condition 2 Current date minus FUP >= 2 Years
*/

select zone_with_cd_name,division_with_cd_name,--plan_code,policy_term,
count(distinct account_num) nop,sum(zeroifnull(total_colln)) colln
from
( select
bpl.zone_with_cd_name,
bpl.division_with_cd_name,
bpl.brn_with_cd_name,
ag.account_num,ag.plan_code,iah.policy_term,
iah.mode_description,iah.premium_amt,
iah.annual_premium_amt_dd ,
ag.next_due_dt, ag.account_open_dt ,insurance_hist_start_dt,insurance_hist_END_dt,
CASE WHEN EXTRACT (MONTH FROM ag.Account_Open_Dt) = 2
then (ag.next_due_dt - ag.account_open_dt + 2 ) /30
else
(ag.next_due_dt - ag.account_open_dt )/30 end mths,
((iah.annual_premium_amt_dd/12) * mths) total_colln
from bo_test.agreement ag
inner join bo_test.insurance_acct_history iah on ag.account_num=iah.account_num
and ag.account_modifier_num='10' and iah.account_modifier_num='10'
and ag.account_open_dt >'2013-12-31' --Condition 1 Date of Commencement >= 01/01/2014 added
on 18072017
and (current_date - ag.next_due_dt)/30 >= 24 --Condition 2 Current date minus FUP >= 2 Years
added on 18072017
and iah.insurance_hist_start_dt between '2012-07-01' and '2015-05-31'
and iah.insurance_hist_end_dt>CURRENT_DATE
and iah.source_val_type in ('41','041')
AND NEXT_DUE_DT <= ADD_MONTHS(MATURITY_DATE,-REGULAR_PREMIUM_PERIOD_NUM)
and iah.account_num<>'603780914'
inner join feaplkp.branch_party_lkp bpl on iah.branch_party_id=bpl.party_id
--and bpl.party_id='2020'
group by 1,2,3,4,5,6,7,8,9,10,11,12,13
having mths<36
)x
group by 1,2--,3,4

You might also like