|
|
@@ -300,6 +300,67 @@
|
|
|
having sum(cost_amount)>1
|
|
|
order by rk asc
|
|
|
</select>
|
|
|
+
|
|
|
+ <select id="optimizerCostRankV2" resultType="java.util.Map">
|
|
|
+ select tb1.user_id, tb4.phonenumber, tb4.nick_name, tb5.dept_id, tb5.dept_name,
|
|
|
+ rank() over (order by sum(cost_amount) desc) as rk,
|
|
|
+ <include refid="costAmount"/>,
|
|
|
+ <include refid="iaaRoi"/>,
|
|
|
+ <include refid="iapRoi"/>,
|
|
|
+ round(sum(dj_cost_amount), 2) as dj_cost_amount,
|
|
|
+ round(sum(mj_cost_amount), 2) as mj_cost_amount
|
|
|
+ from
|
|
|
+ (select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
|
|
|
+ left join
|
|
|
+ (select advertiser_id, sum(iaa_cost_amount) as iaa_cost_amount, sum(iaa_real_cost_amount) as iaa_real_cost_amount,
|
|
|
+ sum(iap_cost_amount) as iap_cost_amount, sum(iap_real_cost_amount) as iap_real_cost_amount,
|
|
|
+ sum(iaa_cost_amount)+sum(iap_cost_amount) as cost_amount,
|
|
|
+ sum(iaa_real_cost_amount)+sum(iap_real_cost_amount) as real_cost_amount,
|
|
|
+ sum(dj_cost_amount) as dj_cost_amount,
|
|
|
+ sum(mj_cost_amount) as mj_cost_amount
|
|
|
+ FROM
|
|
|
+ (select advertiser_id,
|
|
|
+ round(ifnull(sum(case when t2.business_method='IAA' then cost_amount else 0 end), 0), 2) as iaa_cost_amount,
|
|
|
+ round(ifnull(sum(case when t2.business_method='IAA' then real_cost_amount else 0 end), 0), 2) as iaa_real_cost_amount,
|
|
|
+ round(ifnull(sum(case when t2.business_method='IAP' then cost_amount else 0 end), 0), 2) as iap_cost_amount,
|
|
|
+ round(ifnull(sum(case when t2.business_method='IAP' then real_cost_amount else 0 end), 0), 2) as iap_real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(cost_amount, 0) else 0 end) as dj_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(cost_amount, 0) else 0 end) as mj_cost_amount
|
|
|
+ from application.media_ad_report_daily t1
|
|
|
+ join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date=${date} and business_line in (1,6,7,4,8,9,10)
|
|
|
+ group by advertiser_id
|
|
|
+ )subtb2
|
|
|
+ group by advertiser_id
|
|
|
+ ) tb2
|
|
|
+ on tb1.advertiser_id = tb2.advertiser_id
|
|
|
+ left join (select advertiser_id,
|
|
|
+ round(ifnull(sum(share_iaa_amount_3), 0),2) as share_iaa_amount_3,
|
|
|
+ sum(share_iaa_amount) as share_iaa_amount,
|
|
|
+ sum(share_pay_amount) as share_pay_amount
|
|
|
+ from application.user_data_report_daily where stat_date=${date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ group by advertiser_id) tb3
|
|
|
+ on tb1.advertiser_id = tb3.advertiser_id
|
|
|
+ left join (select user_id, nick_name, phonenumber, dept_id, status, del_flag from tidb.deepthink.sys_user) tb4
|
|
|
+ on tb1.user_id=tb4.user_id
|
|
|
+ left join (
|
|
|
+ select dp.dept_id, dp.dept_name, ifnull(subdp.dept_id, dp.dept_id) as sub_dept_id, ifnull(subdp.dept_name, dp.dept_name) as sub_dept_name from (select * from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)) dp
|
|
|
+ right join tidb.deepthink.sys_dept subdp on dp.dept_id=subdp.parent_id
|
|
|
+ where dp.dept_id is not null
|
|
|
+ union all
|
|
|
+ select dept_id, dept_name, dept_id as sub_dept_id, dept_name as sub_dept_name from tidb.deepthink.sys_dept where parent_id in (select dept_id from tidb.deepthink.sys_dept where parent_id=300)
|
|
|
+ ) tb5
|
|
|
+ on tb4.dept_id = tb5.sub_dept_id
|
|
|
+ where tb1.user_id is not null and (tb4.nick_name not like '%IAP%' and tb4.nick_name not like '%IAA%')
|
|
|
+ and tb4.status = 0 and tb4.del_flag = 0
|
|
|
+ group by tb1.user_id, tb4.phonenumber, tb4.nick_name, tb5.dept_id, tb5.dept_name
|
|
|
+ having sum(cost_amount)>1
|
|
|
+ order by rk asc
|
|
|
+ </select>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
<select id="optimizerDateData" resultType="java.util.Map">
|
|
|
select tb1.user_id,tb4.phonenumber,tb4.nick_name, tb5.dept_id,
|
|
|
<include refid="costAmount"/>,
|
|
|
@@ -364,11 +425,18 @@
|
|
|
select tb5.dept_id, tb5.dept_name,
|
|
|
rank() over (order by sum(cost_amount) desc) as rk,
|
|
|
<include refid="costAmount"/>,
|
|
|
+ sum(dj_cost_amount) as dj_cost_amount,
|
|
|
+ sum(mj_cost_amount) as mj_cost_amount,
|
|
|
ifnull(sum(cost_amount_hour), 0) as cost_amount_hour
|
|
|
from
|
|
|
(select cast(advertiser_id as char) advertiser_id, user_id from tidb.deepthink.advertiser_bind_info where user_id is not null) tb1
|
|
|
- left join (select advertiser_id, sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount
|
|
|
- from application.media_ad_report_daily where stat_date=#{date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
+ left join (select advertiser_id, sum(cost_amount) as cost_amount, sum(real_cost_amount) as real_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'DJ' then ifnull(cost_amount, 0) else 0 end) as dj_cost_amount,
|
|
|
+ sum(case t3.movie_type when 'MJ' then ifnull(cost_amount, 0) else 0 end) as mj_cost_amount
|
|
|
+ from application.media_ad_report_daily t1
|
|
|
+ join tidb.deepthink.mini_app_info t2 on t1.ma_appid = t2.app_id
|
|
|
+ join tidb.deepthink.all_moive t3 on t1.movie_id = t3.moive_id and find_in_set(t3.movie_source, t2.movie_sources) > 0
|
|
|
+ where stat_date=#{date} and ma_appid in (select app_id from tidb.deepthink.mini_app_info where business_line in (1,6,7,4,8,9,10))
|
|
|
group by advertiser_id) tb2
|
|
|
on tb1.advertiser_id = tb2.advertiser_id
|
|
|
left join (select advertiser_id, sum(cost_amount) as cost_amount_hour
|