pk_id
NUMBER(20) primary key,
period number(6) not null,
pk_member NUMBER(20) not null,
pk_rate NUMBER(6) not null,
a_balance NUMBER(17,6) default 0 not null,
b_balance NUMBER(17,6) default 0 not null,
a_sum_amount NUMBER(17,6) default 0 not null,
b_sum_amount NUMBER(17,6) default 0 not null,
a_sum_pv NUMBER(17,6) default 0 not null,
b_sum_pv NUMBER(17,6) default 0 not null,
a_new_amount NUMBER(17,6) default 0 not null,
b_new_amount NUMBER(17,6) default 0 not null,
a_new_pv NUMBER(17,6) default 0 not null,
b_new_pv NUMBER(17,6) default 0 not null,
a_sum_real_amount NUMBER(17,6) default 0 not null,
b_sum_real_amount NUMBER(17,6) default 0 not null,
a_sum_real_pv NUMBER(17,6) default 0 not null,
b_sum_real_pv NUMBER(17,6) default 0 not null,
rep_a_balance NUMBER(17,6) default 0 not null,
rep_b_balance NUMBER(17,6) default 0 not null,
rep_a_new_amount NUMBER(17,6) default 0 not null,
rep_b_new_amount NUMBER(17,6) default 0 not null,
rep_a_new_pv NUMBER(17,6) default 0 not null,
rep_b_new_pv NUMBER(17,6) default 0 not null,
rep_a_sum_amount NUMBER(17,6) default 0 not null,
rep_b_sum_amount NUMBER(17,6) default 0 not null,
rep_a_sum_pv NUMBER(17,6) default 0 not null,
rep_b_sum_pv NUMBER(17,6) default 0 not null,
register_amount NUMBER(17,6) default 0 not null,
register_pv NUMBER(17,6) default 0 not null,
register_new_amount NUMBER(17,6) default 0 not null,
register_new_pv NUMBER(17,6) default 0 not null,
upgrade_amount NUMBER(17,6) default 0 not null,
upgrade_pv NUMBER(17,6) default 0 not null,
upgrade_new_amount NUMBER(17,6) default 0 not null,
upgrade_new_pv NUMBER(17,6) default 0 not null,
repurchase_amount NUMBER(17,6) default 0 not null,
repurchase_pv NUMBER(17,6) default 0 not null,
repurchase_new_amount NUMBER(17,6) default 0 not null,
repurchase_new_pv NUMBER(17,6) default 0 not null,
hi_fun_amount NUMBER(17,6) default 0 not null,
hi_fun_pv NUMBER(17,6) default 0 not null,
hi_fun_new_amount NUMBER(17,6) default 0 not null,
hi_fun_new_pv NUMBER(17,6) default 0 not null,
mall_amount NUMBER(17,6) default 0 not null,
mall_pv NUMBER(17,6) default 0 not null,
mall_new_amount NUMBER(17,6) default 0 not null,
mall_new_pv NUMBER(17,6) default 0 not null,
REGISTER_Blo_NEW_PV NUMBER(17,6) default 0 not null,
UPGRADE_Blo_NEW_PV NUMBER(17,6) default 0 not null,
REPURCHASE_Blo_NEW_PV NUMBER(17,6) default 0 not null,
HI_FUN_Blo_NEW_PV NUMBER(17,6) default 0 not null,
MALL_Blo_NEW_PV NUMBER(17,6) default 0 not null,
r_a_balance NUMBER(17,6) default 0 not null,
r_b_balance NUMBER(17,6) default 0 not null,
r_a_sum_amount NUMBER(17,6) default 0 not null,
r_b_sum_amount NUMBER(17,6) default 0 not null,
r_a_sum_pv NUMBER(17,6) default 0 not null,
r_b_sum_pv NUMBER(17,6) default 0 not null,
r_a_sum_real_amount NUMBER(17,6) default 0 not null,
r_b_sum_real_amount NUMBER(17,6) default 0 not null,
r_a_sum_real_pv NUMBER(17,6) default 0 not null,
r_b_sum_real_pv NUMBER(17,6) default 0 not null,
r_rep_a_balance NUMBER(17,6) default 0 not null,
r_rep_b_balance NUMBER(17,6) default 0 not null,
r_rep_a_sum_amount NUMBER(17,6) default 0 not null,
r_rep_b_sum_amount NUMBER(17,6) default 0 not null,
r_rep_a_sum_pv NUMBER(17,6) default 0 not null,
r_rep_b_sum_pv NUMBER(17,6) default 0 not null,
pk_country NUMBER(6) not null,
A_NEW_BOX NUMBER(8) default 0 not null,
B_NEW_BOX NUMBER(8) default 0 not null,
A_SUM_BOX NUMBER(12) default 0 not null,
B_SUM_BOX NUMBER(12) default 0 not null,
TOTAL_NEW_BOX NUMBER(8) default 0 not null,
TOTAL_SUM_BOX NUMBER(12) default 0 not null
create table ${tableName}
(
)
merge into ${tableName} a
using (
select pk_member, max(a.pk_rate) pk_rate,
sum(a_new_amount / bc.out_exchange_rate) a_new_amount,
sum(a_new_pv) a_new_pv,
sum(b_new_amount / bc.out_exchange_rate) b_new_amount,
sum(b_new_pv) b_new_pv,
sum(rep_a_new_amount / bc.out_exchange_rate) rep_a_new_amount,
sum(rep_a_new_pv) rep_a_new_pv,
sum(rep_b_new_amount / bc.out_exchange_rate) rep_b_new_amount,
sum(rep_b_new_pv) rep_b_new_pv,
sum(a_new_real_amount / bc.out_exchange_rate) a_new_real_amount,
sum(a_new_real_pv) a_new_real_pv,
sum(b_new_real_amount / bc.out_exchange_rate) b_new_real_amount,
sum(b_new_real_pv) b_new_real_pv
from (
select pk_place_parent pk_member, #{achieve.pkRate} pk_rate,
(case when place_dept = 1 then #{achieve.newAmount} else 0 end) a_new_amount,
(case when place_dept = 1 then #{achieve.newPv} else 0 end) a_new_pv,
(case when place_dept = 1 then #{achieve.repNewAmount} else 0 end) rep_a_new_amount,
(case when place_dept = 1 then #{achieve.repNewPv} else 0 end) rep_a_new_pv,
(case when place_dept = 1 then #{achieve.newRealAmount} else 0 end) a_new_real_amount,
(case when place_dept = 1 then #{achieve.newRealPv} else 0 end) a_new_real_pv,
(case when place_dept = 2 then #{achieve.newAmount} else 0 end) b_new_amount,
(case when place_dept = 2 then #{achieve.newPv} else 0 end) b_new_pv,
(case when place_dept = 2 then #{achieve.repNewAmount} else 0 end) rep_b_new_amount,
(case when place_dept = 2 then #{achieve.repNewPv} else 0 end) rep_b_new_pv,
(case when place_dept = 2 then #{achieve.newRealAmount} else 0 end) b_new_real_amount,
(case when place_dept = 2 then #{achieve.newRealPv} else 0 end) b_new_real_pv
from(
select pk_place_parent, place_dept from (
select * from ${tableName}
start with pk_member = #{achieve.pkMember}
connect by pk_member = prior pk_place_parent
)
where nvl(pk_place_parent, 0) != 0
)
) a
inner join bd_currency bc
on a.pk_rate = bc.pk_id
group by pk_member
) b
on (a.pk_member = b.pk_member)
when matched then
update
set a.period = a.period + 1,
a.a_sum_pv = a.a_sum_pv - b.a_new_pv,
a.b_sum_pv = a.b_sum_pv - b.b_new_pv,
a.rep_a_sum_pv = a.rep_a_sum_pv - b.rep_a_new_pv,
a.rep_b_sum_pv = a.rep_b_sum_pv - b.rep_b_new_pv,
a.a_sum_real_pv = a.a_sum_real_pv - b.a_new_real_pv,
a.b_sum_real_pv = a.b_sum_real_pv - b.b_new_real_pv
merge into ${tableName} a
using (
select pk_member, max(a.pk_rate) pk_rate,
sum(a_new_amount / bc.out_exchange_rate) a_new_amount,
sum(a_new_pv) a_new_pv,
sum(b_new_amount / bc.out_exchange_rate) b_new_amount,
sum(b_new_pv) b_new_pv,
sum(rep_a_new_amount / bc.out_exchange_rate) rep_a_new_amount,
sum(rep_b_new_amount / bc.out_exchange_rate) rep_b_new_amount,
sum(rep_a_new_pv) rep_a_new_pv,
sum(rep_b_new_pv) rep_b_new_pv,
sum(a_new_real_amount / bc.out_exchange_rate) a_new_real_amount,
sum(a_new_real_pv) a_new_real_pv,
sum(b_new_real_amount / bc.out_exchange_rate) b_new_real_amount,
sum(b_new_real_pv) b_new_real_pv,
sum(a_new_box) a_new_box,
sum(b_new_box) b_new_box
from (
select pk_place_parent pk_member, #{achieve.pkRate} pk_rate,
(case when place_dept = 1 then #{achieve.newAmount} else 0 end) a_new_amount,
(case when place_dept = 1 then #{achieve.newPv} else 0 end) a_new_pv,
(case when place_dept = 1 then #{achieve.repNewAmount} else 0 end) rep_a_new_amount,
(case when place_dept = 1 then #{achieve.repNewPv} else 0 end) rep_a_new_pv,
(case when place_dept = 1 then #{achieve.newRealAmount} else 0 end) a_new_real_amount,
(case when place_dept = 1 then #{achieve.newRealPv} else 0 end) a_new_real_pv,
(case when place_dept = 1 then #{achieve.newBox} else 0 end) a_new_box,
(case when place_dept = 2 then #{achieve.newAmount} else 0 end) b_new_amount,
(case when place_dept = 2 then #{achieve.newPv} else 0 end) b_new_pv,
(case when place_dept = 2 then #{achieve.repNewAmount} else 0 end) rep_b_new_amount,
(case when place_dept = 2 then #{achieve.repNewPv} else 0 end) rep_b_new_pv,
(case when place_dept = 2 then #{achieve.newRealAmount} else 0 end) b_new_real_amount,
(case when place_dept = 2 then #{achieve.newRealPv} else 0 end) b_new_real_pv,
(case when place_dept = 2 then #{achieve.newBox} else 0 end) b_new_box
from(
select pk_place_parent, place_dept from (
select * from ${tableName}
start with pk_member = #{achieve.pkMember}
connect by pk_member = prior pk_place_parent
)
where nvl(pk_place_parent, 0) != 0
)
) a
inner join bd_currency bc
on a.pk_rate = bc.pk_id
group by pk_member
) b
on (a.pk_member = b.pk_member)
when matched then
update set a.period = a.period + 1, a.pk_rate = b.pk_rate,
a.a_sum_pv = a.a_sum_pv + b.a_new_pv,
a.b_sum_pv = a.b_sum_pv + b.b_new_pv,
a.rep_a_sum_pv = a.rep_a_sum_pv + b.rep_a_new_pv,
a.rep_b_sum_pv = a.rep_b_sum_pv + b.rep_b_new_pv,
a.a_sum_real_pv = a.a_sum_real_pv + b.a_new_real_pv,
a.b_sum_real_pv = a.b_sum_real_pv + b.b_new_real_pv,
a.r_a_sum_amount = a.r_a_sum_amount + b.a_new_amount,
a.r_b_sum_amount = a.r_b_sum_amount + b.b_new_amount,
a.r_a_sum_pv = a.r_a_sum_pv + b.a_new_pv,
a.r_b_sum_pv = a.r_b_sum_pv + b.b_new_pv,
a.r_rep_a_sum_amount = a.r_rep_a_sum_amount +b.rep_a_new_amount,
a.r_rep_b_sum_amount = a.r_rep_b_sum_amount + b.rep_b_new_amount,
a.r_rep_a_sum_pv = a.r_rep_a_sum_pv + b.rep_a_new_pv,
a.r_rep_b_sum_pv = a.r_rep_b_sum_pv + b.rep_b_new_pv,
a.r_a_sum_real_amount = a.r_a_sum_real_amount + b.a_new_real_amount,
a.r_b_sum_real_amount = a.r_b_sum_real_amount + b.b_new_real_amount,
a.r_a_sum_real_pv = a.r_a_sum_real_pv + b.a_new_real_pv,
a.r_b_sum_real_pv = a.r_b_sum_real_pv + b.b_new_real_pv,
a.a_new_box = b.a_new_box, a.b_new_box = b.b_new_box, a.total_new_box = b.a_new_box + b.b_new_box,
a.a_sum_box = a.a_sum_box + b.a_new_box, a.b_sum_box = a.b_sum_box + b.b_new_box, a.total_sum_box = a.total_sum_box + b.a_new_box + b.b_new_box
merge into ${targetTable} a
using (select pk_member,
a_balance,
b_balance,
a_sum_amount,
b_sum_amount,
a_sum_pv,
b_sum_pv,
a_new_amount,
b_new_amount,
a_new_pv,
b_new_pv,
a_sum_real_amount,
b_sum_real_amount,
a_sum_real_pv,
b_sum_real_pv,
rep_a_balance,
rep_b_balance,
rep_a_sum_amount,
rep_b_sum_amount,
rep_a_sum_pv,
rep_b_sum_pv,
register_amount,
register_pv,
upgrade_amount,
upgrade_pv,
repurchase_amount,
repurchase_pv,
hi_fun_amount,
hi_fun_pv,
mall_amount,
mall_pv,
pk_country,
min_achieve,
round, second,
net_first_achieve, net_repurchase_achieve,
r_a_balance, r_b_balance,
r_a_sum_amount, r_b_sum_amount,
r_a_sum_pv, r_b_sum_pv,
r_rep_a_sum_amount, r_rep_b_sum_amount,
r_rep_a_sum_pv, r_rep_b_sum_pv,
r_a_sum_real_amount, r_b_sum_real_amount,
r_a_sum_real_pv, r_b_sum_real_pv,
r_rep_a_balance, r_rep_b_balance,
A_SUM_BOX, B_SUM_BOX, TOTAL_SUM_BOX
from ${sourceTable}) b
on (a.pk_member = b.pk_member)
when matched then
update set
a.a_balance = b.a_balance, a.b_balance = b.b_balance,
a.a_sum_amount = b.a_sum_amount, a.b_sum_amount = b.b_sum_amount,
a.a_sum_pv = b.a_sum_pv, a.b_sum_pv = b.b_sum_pv,
a.a_sum_real_amount = b.a_sum_real_amount, a.b_sum_real_amount = b.b_sum_real_amount,
a.a_sum_real_pv = b.a_sum_real_pv, a.b_sum_real_pv = b.b_sum_real_pv,
a.rep_a_balance = b.rep_a_balance, a.rep_b_balance = b.rep_b_balance,
a.rep_a_sum_pv = b.rep_a_sum_pv, a.rep_b_sum_pv = b.rep_b_sum_pv,
a.register_amount = b.register_amount, a.register_pv = b.register_pv,
a.upgrade_amount = b.upgrade_amount, a.upgrade_pv = b.upgrade_pv,
a.repurchase_amount = b.repurchase_amount, a.repurchase_pv = b.repurchase_pv,
a.hi_fun_amount = b.hi_fun_amount, a.hi_fun_pv = b.hi_fun_pv,
a.mall_amount = b.mall_amount, a.mall_pv = b.mall_pv,
a.min_achieve = b.min_achieve, a.round = b.round, a.second = b.second,
a.net_first_achieve = b.net_first_achieve, a.net_repurchase_achieve = b.net_repurchase_achieve,
a.r_a_balance = b.r_a_balance, a.r_b_balance = b.r_b_balance,
a.r_a_sum_amount = b.r_a_sum_amount, a.r_b_sum_amount = b.r_b_sum_amount,
a.r_a_sum_pv = b.r_a_sum_pv, a.r_b_sum_pv = b.r_b_sum_pv,
a.r_rep_a_sum_amount = b.r_rep_a_sum_amount, a.r_rep_b_sum_amount = b.r_rep_b_sum_amount,
a.r_rep_a_sum_pv = b.r_rep_a_sum_pv, a.r_rep_b_sum_pv = b.r_rep_b_sum_pv,
a.r_a_sum_real_amount = b.r_a_sum_real_amount, a.r_b_sum_real_amount = b.r_b_sum_real_amount,
a.r_a_sum_real_pv = b.r_a_sum_real_pv, a.r_b_sum_real_pv = b.r_b_sum_real_pv,
a.r_rep_a_balance = b.r_rep_a_balance, a.r_rep_b_balance = b.r_rep_b_balance,
a.A_SUM_BOX = b.A_SUM_BOX, a.B_SUM_BOX = b.B_SUM_BOX, a.TOTAL_SUM_BOX = b.TOTAL_SUM_BOX
merge into ${targetTable} a
using (select cl.pk_member,
(case infusing_water_type
when 1 then ca.a_sum_real_pv + a_sum_real_modify_pv
when 2 then ca.a_sum_real_pv - a_sum_real_modify_pv
else a_sum_real_modify_pv end) a_sum_real_pv,
(case infusing_water_type
when 1 then ca.b_sum_real_pv + b_sum_real_modify_pv
when 2 then ca.b_sum_real_pv - b_sum_real_modify_pv
else b_sum_real_modify_pv end) b_sum_real_pv,
(case infusing_water_type
when 1 then ca.a_sum_pv + a_first_modify_pv
when 2 then ca.a_sum_pv - a_first_modify_pv
else a_first_modify_pv end) a_sum_pv,
(case infusing_water_type
when 1 then ca.b_sum_pv + b_first_modify_pv
when 2 then ca.b_sum_pv - b_first_modify_pv
else b_first_modify_pv end) b_sum_pv,
(case infusing_water_type
when 1 then ca.a_balance + rep_a_first_modify_balance
when 2 then ca.a_balance - rep_a_first_modify_balance
else rep_a_first_modify_balance end) a_balance,
(case infusing_water_type
when 1 then ca.b_balance + rep_b_first_modify_balance
when 2 then ca.b_balance - rep_b_first_modify_balance
else rep_b_first_modify_balance end) b_balance,
(case infusing_water_type
when 1 then ca.rep_a_sum_pv + rep_a_modify_sum_pv
when 2 then ca.rep_a_sum_pv - rep_a_modify_sum_pv
else rep_a_modify_sum_pv end) rep_a_sum_pv,
(case infusing_water_type
when 1 then ca.rep_b_sum_pv + rep_b_modify_sum_pv
when 2 then ca.rep_b_sum_pv - rep_b_modify_sum_pv
else rep_b_modify_sum_pv end) rep_b_sum_pv,
(case infusing_water_type
when 1 then ca.rep_a_balance + rep_a_modify_balance
when 2 then ca.rep_a_balance - rep_a_modify_balance
else rep_a_modify_balance end) rep_a_balance,
(case infusing_water_type
when 1 then ca.rep_b_balance + rep_b_modify_balance
when 2 then ca.rep_b_balance - rep_b_modify_balance
else rep_b_modify_balance end) rep_b_balance
from cu_member_achieve_log cl
left join ${targetTable} ca
on cl.pk_member = ca.pk_member
where cl.period = #{period}
and approve_status = 5
and cl.pk_id = #{pkId}
order by cl.pk_member, cl.creation_time) b
on (a.pk_member = b.pk_member)
when matched then
update set
a.a_sum_real_pv = b.a_sum_real_pv, a.b_sum_real_pv = b.b_sum_real_pv,
a.a_sum_pv = b.a_sum_pv, a.b_sum_pv = b.b_sum_pv,
a.a_balance = b.a_balance, a.b_balance = b.b_balance,
a.rep_a_sum_pv = b.rep_a_sum_pv, a.rep_b_sum_pv = b.rep_b_sum_pv,
a.rep_a_balance = b.rep_a_balance,a.rep_b_balance = b.rep_b_balance
merge into ${currentTableName} a
using (
select ct.pk_member,
r_a_balance,
r_b_balance,
r_a_sum_pv,
r_b_sum_pv,
r_a_sum_real_pv,
r_b_sum_real_pv,
r_rep_a_sum_pv,
r_rep_b_sum_pv,
r_rep_a_balance,
r_rep_b_balance
from ${yesTableName} ct
inner join cu_member_achieve_log cl
on ct.pk_member = cl.pk_member
where cl.due_date = #{currentDate, jdbcType=DATE}
) b
on (a.pk_member = b.pk_member)
when matched then
update set
a.r_a_balance = b.r_a_balance, a.r_b_balance = b.r_b_balance,
a.r_a_sum_pv = b.r_a_sum_pv, a.r_b_sum_pv = b.r_b_sum_pv,
a.r_a_sum_real_pv = b.r_a_sum_real_pv, a.r_b_sum_real_pv = b.r_b_sum_real_pv,
a.r_rep_a_sum_pv = b.r_rep_a_sum_pv, a.r_rep_b_sum_pv = b.r_rep_b_sum_pv,
a.r_rep_a_balance = b.r_rep_a_balance, a.r_rep_b_balance = b.r_rep_b_balance
merge into ${targetTableName} a
using (
select #{period} period,
pk_member,
nvl(pk_rate, 0) pk_rate,
a_balance,
b_balance,
a_sum_amount,
b_sum_amount,
a_sum_pv,
b_sum_pv,
a_new_amount,
b_new_amount,
a_new_pv,
b_new_pv,
a_sum_real_amount,
b_sum_real_amount,
a_sum_real_pv,
b_sum_real_pv,
rep_a_balance,
rep_b_balance,
rep_a_new_amount,
rep_b_new_amount,
rep_a_new_pv,
rep_b_new_pv,
rep_a_sum_amount,
rep_b_sum_amount,
rep_a_sum_pv,
rep_b_sum_pv,
register_amount,
register_pv,
register_new_amount,
register_new_pv,
upgrade_amount,
upgrade_pv,
upgrade_new_amount,
upgrade_new_pv,
repurchase_amount,
repurchase_pv,
repurchase_new_amount,
repurchase_new_pv,
hi_fun_amount,
hi_fun_pv,
hi_fun_new_amount,
hi_fun_new_pv,
mall_amount,
mall_pv,
mall_new_amount,
mall_new_pv,
register_blo_new_pv,
upgrade_blo_new_pv,
repurchase_blo_new_pv,
hi_fun_blo_new_pv,
mall_blo_new_pv,
r_a_balance,
r_b_balance,
r_a_sum_amount,
r_b_sum_amount,
r_a_sum_pv,
r_b_sum_pv,
r_a_sum_real_amount,
r_b_sum_real_amount,
r_a_sum_real_pv,
r_b_sum_real_pv,
r_rep_a_balance,
r_rep_b_balance,
r_rep_a_sum_amount,
r_rep_b_sum_amount,
r_rep_a_sum_pv,
r_rep_b_sum_pv,
pk_country
from ${sourceTableName}
) b
on (a.pk_member = b.pk_member and a.period = b.period)
WHEN MATCHED THEN
update set a.pk_rate = b.pk_rate,a.a_balance = b.a_balance,a.b_balance = b.b_balance,
a.a_sum_amount = b.a_sum_amount,a.b_sum_amount = b.b_sum_amount,
a.a_sum_pv = b.a_sum_pv,a.b_sum_pv = b.b_sum_pv,a.a_new_amount = b.a_new_amount,
a.b_new_amount = b.b_new_amount,a.a_new_pv = b.a_new_pv,a.b_new_pv = b.b_new_pv,
a.a_sum_real_amount = b.a_sum_real_amount,a.b_sum_real_amount = b.b_sum_real_amount,
a.a_sum_real_pv = b.a_sum_real_pv,a.b_sum_real_pv = b.b_sum_real_pv,
a.rep_a_balance = b.rep_a_balance,a.rep_b_balance = b.rep_b_balance,
a.rep_a_new_amount = b.rep_a_new_amount,a.rep_b_new_amount = b.rep_b_new_amount,
a.rep_a_new_pv = b.rep_a_new_pv,a.rep_b_new_pv = b.rep_b_new_pv,
a.rep_a_sum_amount = b.rep_a_sum_amount,a.rep_b_sum_amount = b.rep_b_sum_amount,
a.rep_a_sum_pv = b.rep_a_sum_pv,a.rep_b_sum_pv = b.rep_b_sum_pv,
a.register_amount = b.register_amount,a.register_pv = b.register_pv,a.register_new_amount = b.register_new_amount,
a.register_new_pv = b.register_new_pv,a.upgrade_amount = b.upgrade_amount,a.upgrade_pv = b.upgrade_pv,
a.upgrade_new_amount = b.upgrade_new_amount,a.upgrade_new_pv = b.upgrade_new_pv,
a.repurchase_amount = b.repurchase_amount,a.repurchase_pv = b.repurchase_pv,
a.repurchase_new_amount = b.repurchase_new_amount,a.repurchase_new_pv = b.repurchase_new_pv,
a.hi_fun_amount = b.hi_fun_amount,a.hi_fun_pv = b.hi_fun_pv,a.hi_fun_new_amount = b.hi_fun_new_amount,
a.hi_fun_new_pv = b.hi_fun_new_pv,a.mall_amount = b.mall_amount,a.mall_pv = b.mall_pv,
a.mall_new_amount = b.mall_new_amount,a.mall_new_pv = b.mall_new_pv,
a.register_blo_new_pv = b.register_blo_new_pv,a.upgrade_blo_new_pv = b.upgrade_blo_new_pv,
a.repurchase_blo_new_pv = b.repurchase_blo_new_pv,
a.hi_fun_blo_new_pv = b.hi_fun_blo_new_pv,a.mall_blo_new_pv = b.mall_blo_new_pv,
a.r_a_balance = b.r_a_balance,a.r_b_balance = b.r_b_balance,a.r_a_sum_amount = b.r_a_sum_amount,
a.r_b_sum_amount = b.r_b_sum_amount,a.r_a_sum_pv = b.r_a_sum_pv,a.r_b_sum_pv = b.r_b_sum_pv,
a.r_a_sum_real_amount = b.r_a_sum_real_amount,a.r_b_sum_real_amount = b.r_b_sum_real_amount,
a.r_a_sum_real_pv = b.r_a_sum_real_pv,a.r_b_sum_real_pv = b.r_b_sum_real_pv,
a.r_rep_a_balance = b.r_rep_a_balance,a.r_rep_b_balance = b.r_rep_b_balance,
a.r_rep_a_sum_amount = b.r_rep_a_sum_amount,a.r_rep_b_sum_amount = b.r_rep_b_sum_amount,
a.r_rep_a_sum_pv = b.r_rep_a_sum_pv,a.r_rep_b_sum_pv = b.r_rep_b_sum_pv,a.pk_country = b.pk_country
WHEN NOT MATCHED THEN
insert (period, pk_member, pk_rate, a_balance, b_balance, a_sum_amount,
b_sum_amount, a_sum_pv, b_sum_pv, a_new_amount, b_new_amount, a_new_pv,
b_new_pv, a_sum_real_amount, b_sum_real_amount, a_sum_real_pv, b_sum_real_pv,
rep_a_balance, rep_b_balance, rep_a_new_amount, rep_b_new_amount, rep_a_new_pv,
rep_b_new_pv, rep_a_sum_amount, rep_b_sum_amount, rep_a_sum_pv, rep_b_sum_pv,
register_amount, register_pv, register_new_amount, register_new_pv,
upgrade_amount, upgrade_pv, upgrade_new_amount, upgrade_new_pv,
repurchase_amount, repurchase_pv, repurchase_new_amount, repurchase_new_pv,
hi_fun_amount, hi_fun_pv, hi_fun_new_amount, hi_fun_new_pv,
mall_amount, mall_pv, mall_new_amount, mall_new_pv,
register_blo_new_pv, upgrade_blo_new_pv, repurchase_blo_new_pv, hi_fun_blo_new_pv,
mall_blo_new_pv,
r_a_balance, r_b_balance, r_a_sum_amount, r_b_sum_amount, r_a_sum_pv, r_b_sum_pv,
r_a_sum_real_amount, r_b_sum_real_amount, r_a_sum_real_pv, r_b_sum_real_pv,
r_rep_a_balance, r_rep_b_balance, r_rep_a_sum_amount, r_rep_b_sum_amount,
r_rep_a_sum_pv, r_rep_b_sum_pv, pk_country)
values (b.period, b.pk_member, b.pk_rate, b.a_balance, b.b_balance, b.a_sum_amount,
b.b_sum_amount, b.a_sum_pv, b.b_sum_pv, b.a_new_amount, b.b_new_amount, b.a_new_pv,
b.b_new_pv, b.a_sum_real_amount, b.b_sum_real_amount, b.a_sum_real_pv, b.b_sum_real_pv,
b.rep_a_balance, b.rep_b_balance, b.rep_a_new_amount, b.rep_b_new_amount, b.rep_a_new_pv,
b.rep_b_new_pv, b.rep_a_sum_amount, b.rep_b_sum_amount, b.rep_a_sum_pv, b.rep_b_sum_pv,
b.register_amount, b.register_pv, b.register_new_amount, b.register_new_pv,
b.upgrade_amount, b.upgrade_pv, b.upgrade_new_amount, b.upgrade_new_pv,
b.repurchase_amount, b.repurchase_pv, b.repurchase_new_amount, b.repurchase_new_pv,
b.hi_fun_amount, b.hi_fun_pv, b.hi_fun_new_amount, b.hi_fun_new_pv,
b.mall_amount, b.mall_pv, b.mall_new_amount, b.mall_new_pv,
b.register_blo_new_pv, b.upgrade_blo_new_pv, b.repurchase_blo_new_pv, b.hi_fun_blo_new_pv,
b.mall_blo_new_pv,
b.r_a_balance, b.r_b_balance, b.r_a_sum_amount, b.r_b_sum_amount, b.r_a_sum_pv,
b.r_b_sum_pv,
b.r_a_sum_real_amount, b.r_b_sum_real_amount, b.r_a_sum_real_pv, b.r_b_sum_real_pv,
b.r_rep_a_balance, b.r_rep_b_balance, b.r_rep_a_sum_amount, b.r_rep_b_sum_amount,
b.r_rep_a_sum_pv, b.r_rep_b_sum_pv, b.pk_country)
update ${targetTableName} a
set a.a_balance = 0,
a.b_balance = 0,
a.a_sum_amount = 0,
a.b_sum_amount = 0,
a.a_sum_pv = 0,
a.b_sum_pv = 0,
a.a_new_amount = 0,
a.b_new_amount = 0,
a.a_new_pv = 0,
a.b_new_pv = 0,
a.a_sum_real_amount = 0,
a.b_sum_real_amount = 0,
a.a_sum_real_pv = 0,
a.b_sum_real_pv = 0,
a.rep_a_balance = 0,
a.rep_b_balance = 0,
a.rep_a_new_amount = 0,
a.rep_b_new_amount = 0,
a.rep_a_new_pv = 0,
a.rep_b_new_pv = 0,
a.rep_a_sum_amount = 0,
a.rep_b_sum_amount = 0,
a.rep_a_sum_pv = 0,
a.rep_b_sum_pv = 0,
a.register_amount = 0,
a.register_pv = 0,
a.register_new_amount = 0,
a.register_new_pv = 0,
a.upgrade_amount = 0,
a.upgrade_pv = 0,
a.upgrade_new_amount = 0,
a.upgrade_new_pv = 0,
a.repurchase_amount = 0,
a.repurchase_pv = 0,
a.repurchase_new_amount = 0,
a.repurchase_new_pv = 0,
a.hi_fun_amount = 0,
a.hi_fun_pv = 0,
a.hi_fun_new_amount = 0,
a.hi_fun_new_pv = 0,
a.mall_amount = 0,
a.mall_pv = 0,
a.mall_new_amount = 0,
a.mall_new_pv = 0,
a.register_blo_new_pv = 0,
a.upgrade_blo_new_pv = 0,
a.repurchase_blo_new_pv = 0,
a.hi_fun_blo_new_pv = 0,
a.mall_blo_new_pv = 0,
a.net_first_achieve = 0,
a.net_repurchase_achieve = 0,
a.min_achieve = 0,
a.round = 0,
a.second = 1,
a.r_a_balance = 0,
a.r_b_balance = 0,
a.r_a_sum_amount = 0,
a.r_b_sum_amount = 0,
a.r_a_sum_pv = 0,
a.r_b_sum_pv = 0,
a.r_rep_a_sum_amount = 0,
a.r_rep_b_sum_amount = 0,
a.r_rep_a_sum_pv = 0,
a.r_rep_b_sum_pv = 0,
a.r_a_sum_real_amount = 0,
a.r_b_sum_real_amount = 0,
a.r_a_sum_real_pv = 0,
a.r_b_sum_real_pv = 0,
a.r_rep_a_balance = 0,
a.r_rep_b_balance = 0,
a.A_NEW_BOX = 0,
a.B_NEW_BOX = 0,
a.A_SUM_BOX = 0,
a.B_SUM_BOX = 0,
a.TOTAL_NEW_BOX = 0,
a.TOTAL_SUM_BOX = 0
merge into ${tableName} a
using (select #{period} period, a.*
from (select user_id pk_member,
sum(CURR_DAY_MAIN_REG_AMOUNT) / 1 REGISTER_AMOUNT,
sum(CURR_DAY_MAIN_REG_PV) / 1 REGISTER_PV,
sum(CURR_DAY_MAIN_UP_AMOUNT) / 1 UPGRADE_AMOUNT,
sum(CURR_DAY_MAIN_UP_PV) / 1 UPGRADE_PV,
sum(CURR_DAY_MAIN_REPUR_AMOUNT) / 1 REPURCHASE_AMOUNT,
sum(CURR_DAY_MAIN_REPURCHASE_PV) / 1 REPURCHASE_PV,
sum(CURR_DAY_SEA2_REG_AMOUNT) / 1 HI_FUN_AMOUNT,
sum(CURR_DAY_SEA2_REG_PV) / 1 HI_FUN_PV,
sum(CURR_DAY_MALL_AMOUNT) / 1 MALL_AMOUNT,
sum(CURR_DAY_MALL_PV) / 1 MALL_PV
from G_MEMBER_ACHIV@link_test
where period between - 729 and #{period}
group by user_id) a) b on
(a.pk_member = b.pk_member and a.period = b.period)
when matched then update set a.REGISTER_AMOUNT = b.REGISTER_AMOUNT,
a.REGISTER_PV = b.REGISTER_PV, a.UPGRADE_AMOUNT = b.UPGRADE_AMOUNT,
a.UPGRADE_PV = b.UPGRADE_PV, a.REPURCHASE_AMOUNT = b.REPURCHASE_AMOUNT,
a.REPURCHASE_PV = b.REPURCHASE_PV, a.HI_FUN_AMOUNT = b.HI_FUN_AMOUNT,
a.HI_FUN_PV = b.HI_FUN_PV, a.MALL_AMOUNT = b.MALL_AMOUNT, a.MALL_PV = b.MALL_PV
create table ${tableName}
(
pk_member NUMBER(20) not null,
pk_parent NUMBER(20) not null,
pk_place_parent NUMBER(20),
place_dept NUMBER(3),
member_code VARCHAR2(30) not null,
member_name VARCHAR2(100) not null,
customer_type NUMBER(2) not null,
phone VARCHAR2(40) not null,
pk_grade NUMBER(4) not null,
pk_awards NUMBER(4) not null,
pk_team_code NUMBER(20),
pk_center_code NUMBER(20),
pk_vertex NUMBER(20) default 1,
pk_settle_country NUMBER(4) not null,
a_sum_pv NUMBER(17,6) default 0 not null,
b_sum_pv NUMBER(17,6) default 0 not null,
rep_a_sum_pv NUMBER(17,6) default 0 not null,
rep_b_sum_pv NUMBER(17,6) default 0 not null,
register_pv NUMBER(17,6) default 0 not null,
upgrade_pv NUMBER(17,6) default 0 not null,
repurchase_pv NUMBER(17,6) default 0 not null,
hi_fun_pv NUMBER(17,6) default 0 not null,
mall_pv NUMBER(17,6) default 0 not null
)
merge into cu_member_month${date} a
using (
select a.*,
b.A_SUM_PV,
b.b_SUM_PV,
b.REGISTER_PV,
b.UPGRADE_PV,
b.REPURCHASE_PV,
b.HI_FUN_PV,
b.MALL_PV
from (
select ct.pk_member,
ct.pk_parent,
ct.pk_place_parent,
ct.place_dept,
ct.member_code,
ct.member_name,
ct.customer_type,
ct.phone,
ct.pk_grade,
ct.pk_awards,
ct.pk_team_code,
ct.pk_center_code,
ct.pk_vertex,
ct.pk_settle_country
from cu_member_tree${date} ct
where period = #{period}) a
inner join(
select pk_member,
sum(A_NEW_PV + REP_A_NEW_PV) A_SUM_PV,
sum(b_NEW_PV + REP_B_NEW_PV) b_SUM_PV,
sum(register_new_pv) REGISTER_PV,
sum(upgrade_new_pv) UPGRADE_PV,
sum(repurchase_new_pv) REPURCHASE_PV,
sum(hi_fun_new_pv) HI_FUN_PV,
sum(mall_new_pv) MALL_PV
from cu_member_achieve${date}
group by pk_member) b
on a.pk_member = b.pk_member
) b
on (a.pk_member = b.pk_member)
when matched then
update set
a.pk_parent = b.pk_parent,a.pk_place_parent = b.pk_place_parent,a.place_dept = b.place_dept,
a.member_code = b.member_code,a.member_name = b.member_name,a.customer_type = b.customer_type,
a.phone = b.phone,a.pk_grade = b.pk_grade,a.pk_awards = b.pk_awards,a.pk_team_code = b.pk_team_code,
a.pk_center_code = b.pk_center_code,a.pk_vertex = b.pk_vertex,a.pk_settle_country = b.pk_settle_country,
a.A_SUM_PV = b.A_SUM_PV,a.b_SUM_PV = b.b_SUM_PV,
a.REGISTER_PV = b.REGISTER_PV,a.UPGRADE_PV = b.UPGRADE_PV,
a.REPURCHASE_PV = b.REPURCHASE_PV,a.HI_FUN_PV = b.HI_FUN_PV,a.MALL_PV = b.MALL_PV
WHEN NOT MATCHED THEN
insert (pk_member, pk_parent, pk_place_parent, place_dept, member_code,
member_name, customer_type, phone, pk_grade, pk_awards, pk_team_code,
pk_center_code, pk_vertex, pk_settle_country, a_sum_pv, b_sum_pv,
register_pv, upgrade_pv, repurchase_pv,
hi_fun_pv, mall_pv)
values (b.pk_member, b.pk_parent, b.pk_place_parent, b.place_dept, b.member_code,
b.member_name, b.customer_type, b.phone, b.pk_grade, b.pk_awards, b.pk_team_code,
b.pk_center_code, b.pk_vertex, b.pk_settle_country, b.a_sum_pv, b.b_sum_pv,
b.register_pv, b.upgrade_pv, b.repurchase_pv,
b.hi_fun_pv, b.mall_pv)
merge into ${targetTable} a
using (
select pk_member,
max(a.pk_rate) pk_rate,
sum(a_new_amount / bc.out_exchange_rate) a_new_amount,
sum(a_new_pv)
a_new_pv,
sum(b_new_amount / bc.out_exchange_rate) b_new_amount,
sum(b_new_pv) b_new_pv,
sum(rep_a_new_amount / bc.out_exchange_rate) rep_a_new_amount,
sum(rep_b_new_amount / bc.out_exchange_rate)
rep_b_new_amount,
sum(rep_a_new_pv) rep_a_new_pv,
sum(rep_b_new_pv) rep_b_new_pv,
sum(a_new_real_amount / bc.out_exchange_rate)
a_new_real_amount,
sum(a_new_real_pv) a_new_real_pv,
sum(b_new_real_amount / bc.out_exchange_rate)
b_new_real_amount,
sum(b_new_real_pv) b_new_real_pv
from (
select pk_place_parent pk_member,
#{achieve.pkRate} pk_rate,
(case when place_dept = 1 then #{achieve.newAmount} else 0 end) a_new_amount,
(case when place_dept = 1 then #{achieve.newPv} else 0 end) a_new_pv,
(case when place_dept = 1 then #{achieve.repNewAmount} else 0 end) rep_a_new_amount,
(case when place_dept = 1 then #{achieve.repNewPv} else 0 end) rep_a_new_pv,
(case when place_dept = 1 then #{achieve.newRealAmount} else 0 end) a_new_real_amount,
(case when place_dept = 1 then #{achieve.newRealPv} else 0 end) a_new_real_pv,
(case when place_dept = 2 then #{achieve.newAmount} else 0 end) b_new_amount,
(case when place_dept = 2 then #{achieve.newPv} else 0 end) b_new_pv,
(case when place_dept = 2 then #{achieve.repNewAmount} else 0 end) rep_b_new_amount,
(case when place_dept = 2 then #{achieve.repNewPv} else 0 end) rep_b_new_pv,
(case when place_dept = 2 then #{achieve.newRealAmount} else 0 end) b_new_real_amount,
(case when place_dept = 2 then #{achieve.newRealPv} else 0 end) b_new_real_pv
from (
select pk_place_parent, place_dept
from (
select *
from (select *
from ${sourceTable}
where period = #{period}) start with pk_member = #{achieve.pkMember}
connect by pk_member = prior pk_place_parent
)
where nvl(pk_place_parent, 0) ! = 0
)
) a
inner join bd_currency bc
on a.pk_rate = bc.pk_id
group by pk_member
) b
on (a.pk_member = b.pk_member)
when matched then
update set
a.a_sum_amount = a.a_sum_amount - b.a_new_amount,
a.b_sum_amount = a.b_sum_amount - b.b_new_amount,
a.a_sum_pv = a.a_sum_pv - b.a_new_pv,
a.b_sum_pv = a.b_sum_pv - b.b_new_pv,
a.rep_a_sum_amount = a.rep_a_sum_amount - b.rep_a_new_amount,
a.rep_b_sum_amount = a.rep_b_sum_amount - b.rep_b_new_amount,
a.rep_a_sum_pv = a.rep_a_sum_pv - b.rep_a_new_pv,
a.rep_b_sum_pv = a.rep_b_sum_pv - b.rep_b_new_pv,
a.a_sum_real_amount = a.a_sum_real_amount - b.a_new_amount - b.rep_a_new_amount,
a.b_sum_real_amount = a.b_sum_real_amount - b.b_new_amount - b.rep_b_new_amount,
a.a_sum_real_pv = a.a_sum_real_pv - b.a_new_pv - b.rep_a_new_pv,
a.b_sum_real_pv = a.b_sum_real_pv - b.b_new_pv - b.rep_b_new_pv,
a.r_a_sum_amount = a.r_a_sum_amount - b.a_new_amount,
a.r_b_sum_amount = a.r_b_sum_amount - b.b_new_amount,
a.r_a_sum_pv = a.r_a_sum_pv - b.a_new_pv,
a.r_b_sum_pv = a.r_b_sum_pv - b.b_new_pv,
a.r_rep_a_sum_amount = a.r_rep_a_sum_amount - b.rep_a_new_amount,
a.r_rep_b_sum_amount = a.r_rep_b_sum_amount - b.rep_b_new_amount,
a.r_rep_a_sum_pv = a.r_rep_a_sum_pv - b.rep_a_new_pv,
a.r_rep_b_sum_pv = a.r_rep_b_sum_pv - b.rep_b_new_pv,
a.r_a_sum_real_amount = a.r_a_sum_real_amount - b.a_new_amount - b.rep_a_new_amount,
a.r_b_sum_real_amount = a.r_b_sum_real_amount - b.b_new_amount - b.rep_b_new_amount,
a.r_a_sum_real_pv = a.r_a_sum_real_pv - b.a_new_pv - b.rep_a_new_pv,
a.r_b_sum_real_pv = a.r_b_sum_real_pv - b.b_new_pv - b.rep_b_new_pv
merge into ${tableName} a
using (
select #{achieve.pkMember} pk_member,
#{achieve.aSumRealPv} a_sum_real_pv,#{achieve.bSumRealPv} b_sum_real_pv,
#{achieve.repANewPv} rep_a_sum_pv,#{achieve.repBNewPv} rep_b_sum_pv,
#{achieve.netFirstAchieve} net_first_achieve,#{achieve.netRepurchaseAchieve} net_repurchase_achieve
from dual
) b
on (a.pk_member = b.pk_member)
when matched then
update set
a.a_sum_real_pv=a.a_sum_real_pv+b.a_sum_real_pv,
a.b_sum_real_pv=a.b_sum_real_pv+b.b_sum_real_pv,
a.rep_a_new_pv=b.rep_a_sum_pv,a.rep_b_new_pv=b.rep_b_sum_pv,
a.net_first_achieve=a.net_first_achieve+b.net_first_achieve,
a.net_repurchase_achieve=a.net_repurchase_achieve+b.net_repurchase_achieve
merge into ${targetTable} a
using (select a.pk_member,
(a.a_sum_real_pv - b.a_sum_real_pv) a_sum_real_pv,
(a.b_sum_real_pv - b.b_sum_real_pv) b_sum_real_pv,
(a.a_sum_pv - b.a_sum_pv) a_sum_pv,
(a.b_sum_pv - b.b_sum_pv) b_sum_pv,
(case
when a.a_balance - b.a_balance < 0 then 0
else a.a_balance - b.a_balance end) a_balance,
(case
when a.b_balance - b.b_balance < 0 then 0
else a.b_balance - b.b_balance end) b_balance,
(a.rep_a_sum_pv - b.rep_a_sum_pv) rep_a_sum_pv,
(a.rep_b_sum_pv - b.rep_b_sum_pv) rep_b_sum_pv,
(case
when a.rep_a_balance - b.rep_a_balance < 0 then 0
else a.rep_a_balance - b.rep_a_balance end) rep_a_balance,
(case
when a.rep_b_balance - b.rep_b_balance < 0 then 0
else a.rep_b_balance - b.rep_b_balance end) rep_b_balance
from ${targetTable} a
inner join(
select pk_member,
sum(a_sum_real_pv) a_sum_real_pv,
sum(B_SUM_REAL_PV) B_SUM_REAL_PV,
sum(A_SUM_PV) A_SUM_PV,
sum(B_SUM_PV) B_SUM_PV,
sum(A_BALANCE) A_BALANCE,
sum(B_BALANCE) B_BALANCE,
sum(REP_A_SUM_PV) REP_A_SUM_PV,
sum(REP_B_SUM_PV) REP_B_SUM_PV,
sum(REP_A_BALANCE) REP_A_BALANCE,
sum(REP_B_BALANCE) REP_B_BALANCE
from (
select pk_id,
pk_member,
pk_country,
(case infusing_water_type
when 1 then a_sum_real_modify_pv
when 2 then -a_sum_real_modify_pv
else a_sum_real_modify_pv - a_sum_real_pv end) a_sum_real_pv,
(case infusing_water_type
when 1 then B_SUM_REAL_MODIFY_PV
when 2 then -B_SUM_REAL_MODIFY_PV
else B_SUM_REAL_MODIFY_PV - B_SUM_REAL_PV end) B_SUM_REAL_PV,
(case infusing_water_type
when 1 then A_FIRST_MODIFY_PV
when 2 then -A_FIRST_MODIFY_PV
else A_FIRST_MODIFY_PV - A_SUM_PV end) A_SUM_PV,
(case infusing_water_type
when 1 then B_FIRST_MODIFY_PV
when 2 then -B_FIRST_MODIFY_PV
else B_FIRST_MODIFY_PV - B_SUM_PV end) B_SUM_PV,
(case infusing_water_type
when 1 then REP_A_FIRST_MODIFY_BALANCE
when 2 then -REP_A_FIRST_MODIFY_BALANCE
else REP_A_FIRST_MODIFY_BALANCE - A_BALANCE end) A_BALANCE,
(case infusing_water_type
when 1 then REP_B_FIRST_MODIFY_BALANCE
when 2 then -REP_B_FIRST_MODIFY_BALANCE
else REP_B_FIRST_MODIFY_BALANCE - B_BALANCE end) B_BALANCE,
(case infusing_water_type
when 1 then REP_A_MODIFY_SUM_PV
when 2 then -REP_A_MODIFY_SUM_PV
else REP_A_MODIFY_SUM_PV - REP_A_SUM_PV end) REP_A_SUM_PV,
(case infusing_water_type
when 1 then REP_B_MODIFY_SUM_PV
when 2 then -REP_B_MODIFY_SUM_PV
else REP_B_MODIFY_SUM_PV - REP_B_SUM_PV end) REP_B_SUM_PV,
(case infusing_water_type
when 1 then REP_A_MODIFY_BALANCE
when 2 then -REP_A_MODIFY_BALANCE
else REP_A_MODIFY_BALANCE - REP_A_BALANCE end) REP_A_BALANCE,
(case infusing_water_type
when 1 then REP_B_MODIFY_BALANCE
when 2 then -REP_B_MODIFY_BALANCE
else REP_B_MODIFY_BALANCE - REP_B_BALANCE end) REP_B_BALANCE
from cu_member_achieve_log
where creation_time >= to_date('2025-02-01', 'yyyy-mm-dd')
and APPROVE_STATUS = 5
and del_flag = 0
and due_date = #{settleDate,jdbcType=DATE}
)
group by pk_member
) b
on b.pk_member = a.pk_member) b
on (a.pk_member = b.pk_member)
when matched then
update set
a.a_sum_real_pv = b.a_sum_real_pv, a.b_sum_real_pv = b.b_sum_real_pv,
a.a_sum_pv = b.a_sum_pv, a.b_sum_pv = b.b_sum_pv,
a.a_balance = b.a_balance, a.b_balance = b.b_balance,
a.rep_a_sum_pv = b.rep_a_sum_pv, a.rep_b_sum_pv = b.rep_b_sum_pv,
a.rep_a_balance = b.rep_a_balance, a.rep_b_balance = b.rep_b_balance
merge into ${targetTable} a
using (select pk_member, a_balance, b_balance, min_achieve, round, second
from ${sourceTable}) b
on (a.pk_member = b.pk_member)
when matched then
update set
a.a_balance = b.a_balance,a.b_balance = b.b_balance,
a.min_achieve = b.min_achieve,a.round = b.round,a.second = b.second
UPDATE ${targetTable} t
SET A_BALANCE = CASE
WHEN t.a_sum_pv > t.b_sum_pv THEN t.a_sum_pv - t.b_sum_pv
ELSE 0
END,
B_BALANCE = CASE
WHEN t.b_sum_pv > t.a_sum_pv THEN t.b_sum_pv - t.a_sum_pv
ELSE 0
END
WHERE t.period = 14
AND t.pk_member IN (
SELECT pk_member
FROM ${targetTable}
WHERE period = #{period}
START WITH pk_member = 20768
CONNECT BY PRIOR pk_member = #{achieve.pkMember}
)
MERGE INTO ${targetTable} t
USING (
SELECT
#{vo.pkMember} as pk_member,
#{vo.period} as period,
#{vo.aBalance} as a_balance,
#{vo.bBalance} as b_balance
) s
ON (t.pk_member = s.pk_member AND t.period = s.period)
WHEN MATCHED THEN
UPDATE SET
t.a_balance = s.a_balance,
t.b_balance = s.b_balance,
t.r_a_balance = s.a_balance,
t.r_b_balance = s.b_balance