zhl 3 роки тому
батько
коміт
2a8a457616
18 змінених файлів з 3052 додано та 6376 видалено
  1. 162 338
      Apietl/bytedance_etl/Q4Task/AppBytedanceAdReportBusi.py
  2. 168 344
      Apietl/bytedance_etl/Q4Task/AppBytedanceAdReportBusiMonth.py
  3. 162 333
      Apietl/bytedance_etl/Q4Task/AppBytedanceAdvertiserReportBusi.py
  4. 162 333
      Apietl/bytedance_etl/Q4Task/AppBytedanceAdvertiserReportBusiMonth.py
  5. 165 342
      Apietl/bytedance_etl/Q4Task/AppBytedanceCampaignReportBusi.py
  6. 165 342
      Apietl/bytedance_etl/Q4Task/AppBytedanceCampaignReportBusiMonth.py
  7. 190 401
      Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyDesignReportBusi.py
  8. 192 393
      Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyDesignReportBusiMonth.py
  9. 166 351
      Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyUserReportBusi.py
  10. 166 346
      Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyUserReportBusiMonth.py
  11. 179 381
      Apietl/bytedance_etl/Q4Task/AppBytedanceImageReportBusi.py
  12. 181 384
      Apietl/bytedance_etl/Q4Task/AppBytedanceImageReportBusiMonth.py
  13. 166 349
      Apietl/bytedance_etl/Q4Task/AppBytedanceProductReportBusi.py
  14. 167 343
      Apietl/bytedance_etl/Q4Task/AppBytedanceProductReportBusiMonth.py
  15. 153 325
      Apietl/bytedance_etl/Q4Task/AppBytedanceProjectReportBusi.py
  16. 153 325
      Apietl/bytedance_etl/Q4Task/AppBytedanceProjectReportBusiMonth.py
  17. 180 376
      Apietl/bytedance_etl/Q4Task/AppBytedanceVideoReportBusi.py
  18. 175 370
      Apietl/bytedance_etl/Q4Task/AppBytedanceVideoReportBusiMonth.py

+ 162 - 338
Apietl/bytedance_etl/Q4Task/AppBytedanceAdReportBusi.py

@@ -202,344 +202,168 @@ group by account_id """
                     FROM
                      (
                       SELECT
-                    advertiser_id account_id,
-                    campaign_id campaign_id,
-                    ad_id,
-                    ad_name,
-                       sum(cost) cost,
-                       sum(`show`) `show`,
-                       round(sum(cost) / sum(`show`), 3) avg_show_cost,
-                       sum(click) click,
-                       round(sum(cost) / sum(`click`), 3) avg_click_cost,
-                       round(
-                        sum(click) / sum(`show`) * 100,
-                        3
-                       ) ctr,
-                       sum(`convert`) `convert`,
-                       round(sum(cost) / sum(`convert`), 3) convert_cost,
-                       round(
-                        sum(`convert`) / sum(click) * 100,
-                        3
-                       ) convert_rate,
-                       sum(deep_convert) deep_convert,
-                       round(
-                        sum(cost) / sum(deep_convert),
-                        3
-                       ) deep_convert_cost,
-                       round(
-                        sum(deep_convert) / sum(`convert`) * 100,
-                        3
-                       ) deep_convert_rate,
-                       sum(attribution_convert) attribution_convert,
-                       round(
-                        sum(cost) / sum(attribution_convert),
-                        3
-                       ) attribution_convert_cost,
-                       sum(attribution_deep_convert) attribution_deep_convert,
-                       round(
-                        sum(cost) / sum(attribution_deep_convert),
-                        3
-                       ) attribution_deep_convert_cost,
-                       sum(download_start) download_start,
-                       round(
-                        sum(cost) / sum(download_start),
-                        3
-                       ) download_start_cost,
-                       round(
-                        sum(download_start) / sum(click),
-                        3
-                       ) download_start_rate,
-                       sum(download_finish) download_finish,
-                       round(
-                        sum(cost) / sum(download_finish),
-                        3
-                       ) download_finish_cost,
-                       round(
-                        sum(download_finish) / sum(download_start) * 100,
-                        3
-                       ) download_finish_rate,
-                       sum(click_install) click_install,
-                       sum(install_finish) install_finish,
-                       round(
-                        sum(cost) / sum(install_finish),
-                        3
-                       ) install_finish_cost,
-                       round(
-                        sum(install_finish) / sum(download_finish) * 100,
-                        3
-                       ) install_finish_rate,
-                       sum(active) active,
-                       round(sum(cost) / sum(active), 3) active_cost,
-                       round(
-                        sum(active) / sum(click) * 100,
-                        3
-                       ) active_rate,
-                       sum(register) register,
-                       round(sum(cost) / sum(register), 3) active_register_cost,
-                       round(
-                        sum(active_register_rate) / {day_count} * 100,
-                        3
-                       ) active_register_rate,
-                       sum(next_day_open) next_day_open,
-                       round(
-                        sum(cost) / sum(next_day_open),
-                        3
-                       ) next_day_open_cost,
-                       round(
-                        sum(next_day_open) / sum(active) * 100,
-                        3
-                       ) next_day_open_rate,
-                       sum(
-                        attribution_next_day_open_cnt
-                       ) attribution_next_day_open_cnt,
-                       round(
-                        sum(cost) / sum(
-                         attribution_next_day_open_cnt
-                        ),
-                        3
-                       ) attribution_next_day_open_cost,
-                       round(
-                        sum(
-                         attribution_next_day_open_cnt
-                        ) / sum(active) * 100,
-                        3
-                       ) attribution_next_day_open_rate,
-                       sum(game_addiction) game_addiction,
-                       round(
-                        sum(cost) / sum(game_addiction),
-                        3
-                       ) game_addiction_cost,
-                       round(
-                        sum(game_addiction_rate) / {day_count} * 100,
-                        3
-                       ) game_addiction_rate,
-                       sum(pay_count) pay_count,
-                       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-                       round(
-                        sum(pay_count) / sum(active) * 100,
-                        3
-                       ) active_pay_rate,
-                       sum(loan_completion) loan_completion,
-                       round(
-                        sum(cost) / sum(loan_completion),
-                        3
-                       ) loan_completion_cost,
-                       round(
-                        sum(loan_completion) / sum(register) * 100,
-                        3
-                       ) loan_completion_rate,
-                       round(sum(pre_loan_credit), 3) pre_loan_credit,
-                       round(
-                        sum(cost) / sum(pre_loan_credit),
-                        3
-                       ) pre_loan_credit_cost,
-                       sum(loan_credit) loan_credit,
-                       round(
-                        sum(cost) / sum(loan_credit),
-                        3
-                       ) loan_credit_cost,
-                       round(
-                        sum(loan_credit) / sum(loan_completion) * 100,
-                        3
-                       ) loan_credit_rate,
-                       sum(in_app_uv) in_app_uv,
-                       sum(in_app_detail_uv) in_app_detail_uv,
-                       sum(in_app_cart) in_app_cart,
-                       sum(in_app_pay) in_app_pay,
-                       sum(in_app_order) in_app_order,
-                       round(
-                        sum(
-                         attribution_game_pay_7d_count
-                        ) / {day_count},
-                        3
-                       ) attribution_game_pay_7d_count,
-                       round(
-                        sum(
-                         attribution_game_pay_7d_cost
-                        ) / {day_count},
-                        3
-                       ) attribution_game_pay_7d_cost,
-                       round(
-                        sum(
-                         attribution_active_pay_7d_per_count
-                        ) / {day_count},
-                        3
-                       ) attribution_active_pay_7d_per_count,
-                       sum(game_pay_cost) game_pay_cost,
-                       sum(game_pay_count) game_pay_count,
-                       sum(phone) phone,
-                       sum(form) form,
-                       sum(map_search) map_search,
-                       sum(button) button,
-                       sum(`view`) `view`,
-                       sum(download) download,
-                       sum(qq) qq,
-                       sum(lottery) lottery,
-                       sum(vote) vote,
-                       sum(message) message,
-                       sum(redirect) redirect,
-                       sum(shopping) shopping,
-                       sum(consult) consult,
-                       sum(wechat) wechat,
-                       sum(phone_confirm) phone_confirm,
-                       sum(phone_connect) phone_connect,
-                       sum(consult_effective) consult_effective,
-                       sum(coupon) coupon,
-                       sum(coupon_single_page) coupon_single_page,
-                       sum(redirect_to_shop) redirect_to_shop,
-                       sum(poi_collect) poi_collect,
-                       sum(poi_address_click) poi_address_click,
-                       sum(luban_order_cnt) luban_order_cnt,
-                       sum(luban_order_stat_amount) luban_order_stat_amount,
-                       sum(luban_order_roi) luban_order_roi,
-                       sum(luban_live_enter_cnt) luban_live_enter_cnt,
-                       sum(
-                        live_watch_one_minute_count
-                       ) live_watch_one_minute_count,
-                       sum(luban_live_follow_cnt) luban_live_follow_cnt,
-                       sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
-                       sum(luban_live_comment_cnt) luban_live_comment_cnt,
-                       sum(luban_live_share_cnt) luban_live_share_cnt,
-                       sum(luban_live_gift_cnt) luban_live_gift_cnt,
-                       sum(luban_live_gift_amount) luban_live_gift_amount,
-                       sum(
-                        luban_live_slidecart_click_cnt
-                       ) luban_live_slidecart_click_cnt,
-                       sum(
-                        luban_live_click_product_cnt
-                       ) luban_live_click_product_cnt,
-                       sum(luban_live_pay_order_count) luban_live_pay_order_count,
-                       sum(
-                        luban_live_pay_order_stat_cost
-                       ) luban_live_pay_order_stat_cost,
-                       sum(live_component_click_count) live_component_click_count,
-                       round(
-                        sum(cost) / sum(live_component_click_count),
-                        3
-                       ) live_component_click_cost,
-                       round(
-                        sum(live_component_click_count) / {day_count} * 100,
-                        3
-                       ) live_component_click_rate,
-                       sum(wechat_login_count) wechat_login_count,
-                       sum(
-                        attribution_wechat_login_30d_count
-                       ) attribution_wechat_login_30d_count,
-                       round(
-                        sum(cost) / sum(wechat_login_count),
-                        3
-                       ) wechat_login_cost,
-                       round(
-                        sum(cost) / sum(
-                         attribution_wechat_login_30d_count
-                        ),
-                        3
-                       ) attribution_wechat_login_30d_cost,
-                       sum(wechat_first_pay_count) wechat_first_pay_count,
-                       sum(
-                        attribution_wechat_first_pay_30d_count
-                       ) attribution_wechat_first_pay_30d_count,
-                       round(
-                        sum(cost) / sum(wechat_first_pay_count),
-                        3
-                       ) wechat_first_pay_cost,
-                       round(
-                        sum(cost) / sum(
-                         attribution_wechat_first_pay_30d_count
-                        ),
-                        3
-                       ) attribution_wechat_first_pay_30d_cost,
-                       round(
-                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-                        3
-                       ) wechat_first_pay_rate,
-                       round(
-                        sum(
-                         attribution_wechat_first_pay_30d_count
-                        ) / sum(
-                         attribution_wechat_login_30d_count
-                        ) * 100,
-                        3
-                       ) attribution_wechat_first_pay_30d_rate,
-                       sum(wechat_pay_amount) wechat_pay_amount,
-                       sum(
-                        attribution_wechat_pay_30d_amount
-                       ) attribution_wechat_pay_30d_amount,
-                       sum(
-                        attribution_wechat_pay_30d_roi
-                       ) attribution_wechat_pay_30d_roi,
-                       sum(phone_effective) phone_effective,
-                       sum(total_play) total_play,
-                       sum(valid_play) valid_play,
-                       round(
-                        sum(cost) / sum(valid_play),
-                        3
-                       ) valid_play_cost,
-                       round(
-                        sum(valid_play) / sum(`show`) * 100,
-                        3
-                       ) valid_play_rate,
-                       sum(play_25_feed_break) play_25_feed_break,
-                       sum(play_50_feed_break) play_50_feed_break,
-                       sum(play_75_feed_break) play_75_feed_break,
-                       sum(play_100_feed_break) play_100_feed_break,
-                       round(
-                        sum(average_play_time_per_play) / {day_count},
-                        3
-                       ) average_play_time_per_play,
-                       round(
-                        sum(play_over_rate) / {day_count} * 100,
-                        3
-                       ) play_over_rate,
-                       round(
-                        sum(wifi_play) / sum(total_play) * 100,
-                        3
-                       ) wifi_play_rate,
-                       sum(wifi_play) wifi_play,
-                       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-                       sum(
-                        advanced_creative_phone_click
-                       ) advanced_creative_phone_click,
-                       sum(
-                        advanced_creative_counsel_click
-                       ) advanced_creative_counsel_click,
-                       sum(
-                        advanced_creative_form_click
-                       ) advanced_creative_form_click,
-                       sum(
-                        advanced_creative_coupon_addition
-                       ) advanced_creative_coupon_addition,
-                       sum(
-                        advanced_creative_form_submit
-                       ) advanced_creative_form_submit,
-                       sum(card_show) card_show,
-                       sum(`share`) `share`,
-                       sum(`comment`) `comment`,
-                       sum(`like`) `like`,
-                       sum(follow) follow,
-                       sum(home_visited) home_visited,
-                       sum(ies_challenge_click) ies_challenge_click,
-                       sum(ies_music_click) ies_music_click,
-                       sum(location_click) location_click,
-                       sum(message_action) message_action,
-                       sum(click_landing_page) click_landing_page,
-                       sum(click_shopwindow) click_shopwindow,
-                       sum(click_website) click_website,
-                       sum(click_download) click_download,
-                       sum(click_call_dy) click_call_dy,
-                       sum(submit_certification_count) submit_certification_count,
-                       sum(approval_count) approval_count,
-                       sum(first_order_count) first_rental_order_count,
-                       sum(first_rental_order_count) first_order_count,
-                       sum(commute_first_pay_count) commute_first_pay_count
-                      FROM
-                       `media_api`.bytedance_ad_report_daily
-                      WHERE
-                       stat_datetime >= date_format(
-                        date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),
-                        '%Y%m%d'
-                       ) and advertiser_id={account_id}
-                      GROUP BY
+                        advertiser_id account_id,
+                        campaign_id campaign_id,
+                        ad_id,
+                        ad_name,
+                        sum(cost) cost,
+                        sum(`show`) `show`,
+                        ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+                        sum(click)click,
+                        ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+                        ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+                        sum(`convert`)`convert`,
+                        ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+                        ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+                        sum(deep_convert) deep_convert,
+                        ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+                        ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+                        sum(attribution_convert)attribution_convert,
+                        ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+                        sum(attribution_deep_convert) attribution_deep_convert,
+                        ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+                        sum(download_start) download_start,
+                        ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+                        ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+                        sum(download_finish) download_finish,
+                        ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+                        ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+                        sum(click_install)click_install,
+                        sum(install_finish) install_finish,
+                        ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+                        ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+                        sum(active) active,
+                        ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+                        ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+                        sum(register)register,
+                        ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+                        ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+                        sum(next_day_open)next_day_open,
+                        ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+                        ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+                        sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+                        ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+                        ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+                        sum(game_addiction) game_addiction,
+                        ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+                        ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+                        sum(pay_count)pay_count,
+                        ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+                        ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+                        sum(loan_completion) loan_completion,
+                        ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+                        ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+                        ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+                        ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+                        sum(loan_credit)loan_credit,
+                        ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+                        ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+                        sum(in_app_uv)in_app_uv,
+                        sum(in_app_detail_uv) in_app_detail_uv,
+                        sum(in_app_cart)in_app_cart,
+                        sum(in_app_pay) in_app_pay,
+                        sum(in_app_order) in_app_order,
+                        ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+                        ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+                        ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+                        sum(game_pay_cost)game_pay_cost,
+                        sum(game_pay_count) game_pay_count,
+                        sum(phone)phone,
+                        sum(form) form,
+                        sum(map_search) map_search,
+                        sum(button) button,
+                        sum(`view`) `view`,
+                        sum(download)download,
+                        sum(qq)qq,
+                        sum(lottery)lottery,
+                        sum(vote) vote,
+                        sum(message)message,
+                        sum(redirect)redirect,
+                        sum(shopping)shopping,
+                        sum(consult)consult,
+                        sum(wechat) wechat,
+                        sum(phone_confirm)phone_confirm,
+                        sum(phone_connect)phone_connect,
+                        sum(consult_effective)consult_effective,
+                        sum(coupon) coupon,
+                        sum(coupon_single_page) coupon_single_page,
+                        sum(redirect_to_shop) redirect_to_shop,
+                        sum(poi_collect)poi_collect,
+                        sum(poi_address_click)poi_address_click,
+                        sum(luban_order_cnt) luban_order_cnt,
+                        sum(luban_order_stat_amount)luban_order_stat_amount,
+                        sum(luban_order_roi) luban_order_roi,
+                        sum(luban_live_enter_cnt) luban_live_enter_cnt,
+                        sum(live_watch_one_minute_count) live_watch_one_minute_count,
+                        sum(luban_live_follow_cnt) luban_live_follow_cnt,
+                        sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+                        sum(luban_live_comment_cnt) luban_live_comment_cnt,
+                        sum(luban_live_share_cnt) luban_live_share_cnt,
+                        sum(luban_live_gift_cnt)luban_live_gift_cnt,
+                        sum(luban_live_gift_amount) luban_live_gift_amount,
+                        sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+                        sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+                        sum(luban_live_pay_order_count) luban_live_pay_order_count,
+                        sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+                        sum(live_component_click_count) live_component_click_count,
+                        ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+                        ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+                        sum(wechat_login_count) wechat_login_count,
+                        sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+                        ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+                        ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+                        sum(wechat_first_pay_count) wechat_first_pay_count,
+                        sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+                        ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+                        ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+                        ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+                        ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+                        sum(wechat_pay_amount)wechat_pay_amount,
+                        sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+                        sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+                        sum(phone_effective) phone_effective,
+                        sum(total_play) total_play,
+                        sum(valid_play) valid_play,
+                        ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+                        ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+                        sum(play_25_feed_break) play_25_feed_break,
+                        sum(play_50_feed_break) play_50_feed_break,
+                        sum(play_75_feed_break) play_75_feed_break,
+                        sum(play_100_feed_break)play_100_feed_break,
+                        ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+                        ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+                        ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+                        sum(wifi_play)wifi_play,
+                        ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+                        sum(advanced_creative_phone_click) advanced_creative_phone_click,
+                        sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+                        sum(advanced_creative_form_click) advanced_creative_form_click,
+                        sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+                        sum(advanced_creative_form_submit) advanced_creative_form_submit,
+                        sum(card_show)card_show,
+                        sum(`share`)`share`,
+                        sum(`comment`)`comment`,
+                        sum(`like`) `like`,
+                        sum(follow) follow,
+                        sum(home_visited) home_visited,
+                        sum(ies_challenge_click)ies_challenge_click,
+                        sum(ies_music_click) ies_music_click,
+                        sum(location_click) location_click,
+                        sum(message_action) message_action,
+                        sum(click_landing_page) click_landing_page,
+                        sum(click_shopwindow) click_shopwindow,
+                        sum(click_website)click_website,
+                        sum(click_download) click_download,
+                        sum(click_call_dy)click_call_dy,
+                        sum(submit_certification_count) submit_certification_count,
+                        sum(approval_count) approval_count,
+                        sum(first_order_count)first_rental_order_count,
+                        sum(first_rental_order_count) first_order_count,
+                        sum(commute_first_pay_count)commute_first_pay_count
+                      FROM `media_api`.bytedance_ad_report_daily
+                      WHERE stat_datetime >= date_format(
+                       date_sub(({date_time}, INTERVAL {day_count}-1 DAY),'%Y%m%d') and advertiser_id={account_id}
+                    GROUP BY
                     advertiser_id,
                     campaign_id,
                     ad_id,

+ 168 - 344
Apietl/bytedance_etl/Q4Task/AppBytedanceAdReportBusiMonth.py

@@ -203,350 +203,174 @@ group by account_id """
                     FROM
                      (
                       SELECT
-                    advertiser_id account_id,
-                    campaign_id campaign_id,
-                    ad_id,
-                    ad_name,
-                       sum(cost) cost,
-                       sum(`show`) `show`,
-                       round(sum(cost) / sum(`show`), 3) avg_show_cost,
-                       sum(click) click,
-                       round(sum(cost) / sum(`click`), 3) avg_click_cost,
-                       round(
-                        sum(click) / sum(`show`) * 100,
-                        3
-                       ) ctr,
-                       sum(`convert`) `convert`,
-                       round(sum(cost) / sum(`convert`), 3) convert_cost,
-                       round(
-                        sum(`convert`) / sum(click) * 100,
-                        3
-                       ) convert_rate,
-                       sum(deep_convert) deep_convert,
-                       round(
-                        sum(cost) / sum(deep_convert),
-                        3
-                       ) deep_convert_cost,
-                       round(
-                        sum(deep_convert) / sum(`convert`) * 100,
-                        3
-                       ) deep_convert_rate,
-                       sum(attribution_convert) attribution_convert,
-                       round(
-                        sum(cost) / sum(attribution_convert),
-                        3
-                       ) attribution_convert_cost,
-                       sum(attribution_deep_convert) attribution_deep_convert,
-                       round(
-                        sum(cost) / sum(attribution_deep_convert),
-                        3
-                       ) attribution_deep_convert_cost,
-                       sum(download_start) download_start,
-                       round(
-                        sum(cost) / sum(download_start),
-                        3
-                       ) download_start_cost,
-                       round(
-                        sum(download_start) / sum(click),
-                        3
-                       ) download_start_rate,
-                       sum(download_finish) download_finish,
-                       round(
-                        sum(cost) / sum(download_finish),
-                        3
-                       ) download_finish_cost,
-                       round(
-                        sum(download_finish) / sum(download_start) * 100,
-                        3
-                       ) download_finish_rate,
-                       sum(click_install) click_install,
-                       sum(install_finish) install_finish,
-                       round(
-                        sum(cost) / sum(install_finish),
-                        3
-                       ) install_finish_cost,
-                       round(
-                        sum(install_finish) / sum(download_finish) * 100,
-                        3
-                       ) install_finish_rate,
-                       sum(active) active,
-                       round(sum(cost) / sum(active), 3) active_cost,
-                       round(
-                        sum(active) / sum(click) * 100,
-                        3
-                       ) active_rate,
-                       sum(register) register,
-                       round(sum(cost) / sum(register), 3) active_register_cost,
-                       round(
-                        sum(active_register_rate) / {day_count} * 100,
-                        3
-                       ) active_register_rate,
-                       sum(next_day_open) next_day_open,
-                       round(
-                        sum(cost) / sum(next_day_open),
-                        3
-                       ) next_day_open_cost,
-                       round(
-                        sum(next_day_open) / sum(active) * 100,
-                        3
-                       ) next_day_open_rate,
-                       sum(
-                        attribution_next_day_open_cnt
-                       ) attribution_next_day_open_cnt,
-                       round(
-                        sum(cost) / sum(
-                         attribution_next_day_open_cnt
-                        ),
-                        3
-                       ) attribution_next_day_open_cost,
-                       round(
-                        sum(
-                         attribution_next_day_open_cnt
-                        ) / sum(active) * 100,
-                        3
-                       ) attribution_next_day_open_rate,
-                       sum(game_addiction) game_addiction,
-                       round(
-                        sum(cost) / sum(game_addiction),
-                        3
-                       ) game_addiction_cost,
-                       round(
-                        sum(game_addiction_rate) / {day_count} * 100,
-                        3
-                       ) game_addiction_rate,
-                       sum(pay_count) pay_count,
-                       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-                       round(
-                        sum(pay_count) / sum(active) * 100,
-                        3
-                       ) active_pay_rate,
-                       sum(loan_completion) loan_completion,
-                       round(
-                        sum(cost) / sum(loan_completion),
-                        3
-                       ) loan_completion_cost,
-                       round(
-                        sum(loan_completion) / sum(register) * 100,
-                        3
-                       ) loan_completion_rate,
-                       round(sum(pre_loan_credit), 3) pre_loan_credit,
-                       round(
-                        sum(cost) / sum(pre_loan_credit),
-                        3
-                       ) pre_loan_credit_cost,
-                       sum(loan_credit) loan_credit,
-                       round(
-                        sum(cost) / sum(loan_credit),
-                        3
-                       ) loan_credit_cost,
-                       round(
-                        sum(loan_credit) / sum(loan_completion) * 100,
-                        3
-                       ) loan_credit_rate,
-                       sum(in_app_uv) in_app_uv,
-                       sum(in_app_detail_uv) in_app_detail_uv,
-                       sum(in_app_cart) in_app_cart,
-                       sum(in_app_pay) in_app_pay,
-                       sum(in_app_order) in_app_order,
-                       round(
-                        sum(
-                         attribution_game_pay_7d_count
-                        ) / {day_count},
-                        3
-                       ) attribution_game_pay_7d_count,
-                       round(
-                        sum(
-                         attribution_game_pay_7d_cost
-                        ) / {day_count},
-                        3
-                       ) attribution_game_pay_7d_cost,
-                       round(
-                        sum(
-                         attribution_active_pay_7d_per_count
-                        ) / {day_count},
-                        3
-                       ) attribution_active_pay_7d_per_count,
-                       sum(game_pay_cost) game_pay_cost,
-                       sum(game_pay_count) game_pay_count,
-                       sum(phone) phone,
-                       sum(form) form,
-                       sum(map_search) map_search,
-                       sum(button) button,
-                       sum(`view`) `view`,
-                       sum(download) download,
-                       sum(qq) qq,
-                       sum(lottery) lottery,
-                       sum(vote) vote,
-                       sum(message) message,
-                       sum(redirect) redirect,
-                       sum(shopping) shopping,
-                       sum(consult) consult,
-                       sum(wechat) wechat,
-                       sum(phone_confirm) phone_confirm,
-                       sum(phone_connect) phone_connect,
-                       sum(consult_effective) consult_effective,
-                       sum(coupon) coupon,
-                       sum(coupon_single_page) coupon_single_page,
-                       sum(redirect_to_shop) redirect_to_shop,
-                       sum(poi_collect) poi_collect,
-                       sum(poi_address_click) poi_address_click,
-                       sum(luban_order_cnt) luban_order_cnt,
-                       sum(luban_order_stat_amount) luban_order_stat_amount,
-                       sum(luban_order_roi) luban_order_roi,
-                       sum(luban_live_enter_cnt) luban_live_enter_cnt,
-                       sum(
-                        live_watch_one_minute_count
-                       ) live_watch_one_minute_count,
-                       sum(luban_live_follow_cnt) luban_live_follow_cnt,
-                       sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
-                       sum(luban_live_comment_cnt) luban_live_comment_cnt,
-                       sum(luban_live_share_cnt) luban_live_share_cnt,
-                       sum(luban_live_gift_cnt) luban_live_gift_cnt,
-                       sum(luban_live_gift_amount) luban_live_gift_amount,
-                       sum(
-                        luban_live_slidecart_click_cnt
-                       ) luban_live_slidecart_click_cnt,
-                       sum(
-                        luban_live_click_product_cnt
-                       ) luban_live_click_product_cnt,
-                       sum(luban_live_pay_order_count) luban_live_pay_order_count,
-                       sum(
-                        luban_live_pay_order_stat_cost
-                       ) luban_live_pay_order_stat_cost,
-                       sum(live_component_click_count) live_component_click_count,
-                       round(
-                        sum(cost) / sum(live_component_click_count),
-                        3
-                       ) live_component_click_cost,
-                       round(
-                        sum(live_component_click_count) / {day_count} * 100,
-                        3
-                       ) live_component_click_rate,
-                       sum(wechat_login_count) wechat_login_count,
-                       sum(
-                        attribution_wechat_login_30d_count
-                       ) attribution_wechat_login_30d_count,
-                       round(
-                        sum(cost) / sum(wechat_login_count),
-                        3
-                       ) wechat_login_cost,
-                       round(
-                        sum(cost) / sum(
-                         attribution_wechat_login_30d_count
-                        ),
-                        3
-                       ) attribution_wechat_login_30d_cost,
-                       sum(wechat_first_pay_count) wechat_first_pay_count,
-                       sum(
-                        attribution_wechat_first_pay_30d_count
-                       ) attribution_wechat_first_pay_30d_count,
-                       round(
-                        sum(cost) / sum(wechat_first_pay_count),
-                        3
-                       ) wechat_first_pay_cost,
-                       round(
-                        sum(cost) / sum(
-                         attribution_wechat_first_pay_30d_count
-                        ),
-                        3
-                       ) attribution_wechat_first_pay_30d_cost,
-                       round(
-                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-                        3
-                       ) wechat_first_pay_rate,
-                       round(
-                        sum(
-                         attribution_wechat_first_pay_30d_count
-                        ) / sum(
-                         attribution_wechat_login_30d_count
-                        ) * 100,
-                        3
-                       ) attribution_wechat_first_pay_30d_rate,
-                       sum(wechat_pay_amount) wechat_pay_amount,
-                       sum(
-                        attribution_wechat_pay_30d_amount
-                       ) attribution_wechat_pay_30d_amount,
-                       sum(
-                        attribution_wechat_pay_30d_roi
-                       ) attribution_wechat_pay_30d_roi,
-                       sum(phone_effective) phone_effective,
-                       sum(total_play) total_play,
-                       sum(valid_play) valid_play,
-                       round(
-                        sum(cost) / sum(valid_play),
-                        3
-                       ) valid_play_cost,
-                       round(
-                        sum(valid_play) / sum(`show`) * 100,
-                        3
-                       ) valid_play_rate,
-                       sum(play_25_feed_break) play_25_feed_break,
-                       sum(play_50_feed_break) play_50_feed_break,
-                       sum(play_75_feed_break) play_75_feed_break,
-                       sum(play_100_feed_break) play_100_feed_break,
-                       round(
-                        sum(average_play_time_per_play) / {day_count},
-                        3
-                       ) average_play_time_per_play,
-                       round(
-                        sum(play_over_rate) / {day_count} * 100,
-                        3
-                       ) play_over_rate,
-                       round(
-                        sum(wifi_play) / sum(total_play) * 100,
-                        3
-                       ) wifi_play_rate,
-                       sum(wifi_play) wifi_play,
-                       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-                       sum(
-                        advanced_creative_phone_click
-                       ) advanced_creative_phone_click,
-                       sum(
-                        advanced_creative_counsel_click
-                       ) advanced_creative_counsel_click,
-                       sum(
-                        advanced_creative_form_click
-                       ) advanced_creative_form_click,
-                       sum(
-                        advanced_creative_coupon_addition
-                       ) advanced_creative_coupon_addition,
-                       sum(
-                        advanced_creative_form_submit
-                       ) advanced_creative_form_submit,
-                       sum(card_show) card_show,
-                       sum(`share`) `share`,
-                       sum(`comment`) `comment`,
-                       sum(`like`) `like`,
-                       sum(follow) follow,
-                       sum(home_visited) home_visited,
-                       sum(ies_challenge_click) ies_challenge_click,
-                       sum(ies_music_click) ies_music_click,
-                       sum(location_click) location_click,
-                       sum(message_action) message_action,
-                       sum(click_landing_page) click_landing_page,
-                       sum(click_shopwindow) click_shopwindow,
-                       sum(click_website) click_website,
-                       sum(click_download) click_download,
-                       sum(click_call_dy) click_call_dy,
-                       sum(submit_certification_count) submit_certification_count,
-                       sum(approval_count) approval_count,
-                       sum(first_order_count) first_rental_order_count,
-                       sum(first_rental_order_count) first_order_count,
-                       sum(commute_first_pay_count) commute_first_pay_count
-                      FROM
-                       `media_api`.bytedance_ad_report_daily
-                      WHERE
-                       stat_datetime >= date_format(
-                        date_sub({date_time}, INTERVAL {day_count} DAY),
-                        '%Y%m%d'
-                       )
-                       and advertiser_id = {account_id}
-                      GROUP BY
-                    advertiser_id,
-                    campaign_id,
-                    ad_id,
-                    ad_name
-                     ) report
+                        advertiser_id account_id,
+                        campaign_id campaign_id,
+                        ad_id,
+                        ad_name,
+                        sum(cost) cost,
+                        sum(`show`) `show`,
+                        ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+                        sum(click)click,
+                        ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+                        ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+                        sum(`convert`)`convert`,
+                        ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+                        ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+                        sum(deep_convert) deep_convert,
+                        ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+                        ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+                        sum(attribution_convert)attribution_convert,
+                        ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+                        sum(attribution_deep_convert) attribution_deep_convert,
+                        ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+                        sum(download_start) download_start,
+                        ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+                        ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+                        sum(download_finish) download_finish,
+                        ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+                        ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+                        sum(click_install)click_install,
+                        sum(install_finish) install_finish,
+                        ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+                        ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+                        sum(active) active,
+                        ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+                        ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+                        sum(register)register,
+                        ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+                        ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+                        sum(next_day_open)next_day_open,
+                        ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+                        ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+                        sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+                        ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+                        ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+                        sum(game_addiction) game_addiction,
+                        ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+                        ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+                        sum(pay_count)pay_count,
+                        ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+                        ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+                        sum(loan_completion) loan_completion,
+                        ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+                        ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+                        ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+                        ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+                        sum(loan_credit)loan_credit,
+                        ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+                        ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+                        sum(in_app_uv)in_app_uv,
+                        sum(in_app_detail_uv) in_app_detail_uv,
+                        sum(in_app_cart)in_app_cart,
+                        sum(in_app_pay) in_app_pay,
+                        sum(in_app_order) in_app_order,
+                        ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+                        ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+                        ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+                        sum(game_pay_cost)game_pay_cost,
+                        sum(game_pay_count) game_pay_count,
+                        sum(phone)phone,
+                        sum(form) form,
+                        sum(map_search) map_search,
+                        sum(button) button,
+                        sum(`view`) `view`,
+                        sum(download)download,
+                        sum(qq)qq,
+                        sum(lottery)lottery,
+                        sum(vote) vote,
+                        sum(message)message,
+                        sum(redirect)redirect,
+                        sum(shopping)shopping,
+                        sum(consult)consult,
+                        sum(wechat) wechat,
+                        sum(phone_confirm)phone_confirm,
+                        sum(phone_connect)phone_connect,
+                        sum(consult_effective)consult_effective,
+                        sum(coupon) coupon,
+                        sum(coupon_single_page) coupon_single_page,
+                        sum(redirect_to_shop) redirect_to_shop,
+                        sum(poi_collect)poi_collect,
+                        sum(poi_address_click)poi_address_click,
+                        sum(luban_order_cnt) luban_order_cnt,
+                        sum(luban_order_stat_amount)luban_order_stat_amount,
+                        sum(luban_order_roi) luban_order_roi,
+                        sum(luban_live_enter_cnt) luban_live_enter_cnt,
+                        sum(live_watch_one_minute_count) live_watch_one_minute_count,
+                        sum(luban_live_follow_cnt) luban_live_follow_cnt,
+                        sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+                        sum(luban_live_comment_cnt) luban_live_comment_cnt,
+                        sum(luban_live_share_cnt) luban_live_share_cnt,
+                        sum(luban_live_gift_cnt)luban_live_gift_cnt,
+                        sum(luban_live_gift_amount) luban_live_gift_amount,
+                        sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+                        sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+                        sum(luban_live_pay_order_count) luban_live_pay_order_count,
+                        sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+                        sum(live_component_click_count) live_component_click_count,
+                        ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+                        ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+                        sum(wechat_login_count) wechat_login_count,
+                        sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+                        ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+                        ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+                        sum(wechat_first_pay_count) wechat_first_pay_count,
+                        sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+                        ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+                        ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+                        ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+                        ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+                        sum(wechat_pay_amount)wechat_pay_amount,
+                        sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+                        sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+                        sum(phone_effective) phone_effective,
+                        sum(total_play) total_play,
+                        sum(valid_play) valid_play,
+                        ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+                        ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+                        sum(play_25_feed_break) play_25_feed_break,
+                        sum(play_50_feed_break) play_50_feed_break,
+                        sum(play_75_feed_break) play_75_feed_break,
+                        sum(play_100_feed_break)play_100_feed_break,
+                        ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+                        ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+                        ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+                        sum(wifi_play)wifi_play,
+                        ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+                        sum(advanced_creative_phone_click) advanced_creative_phone_click,
+                        sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+                        sum(advanced_creative_form_click) advanced_creative_form_click,
+                        sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+                        sum(advanced_creative_form_submit) advanced_creative_form_submit,
+                        sum(card_show)card_show,
+                        sum(`share`)`share`,
+                        sum(`comment`)`comment`,
+                        sum(`like`) `like`,
+                        sum(follow) follow,
+                        sum(home_visited) home_visited,
+                        sum(ies_challenge_click)ies_challenge_click,
+                        sum(ies_music_click) ies_music_click,
+                        sum(location_click) location_click,
+                        sum(message_action) message_action,
+                        sum(click_landing_page) click_landing_page,
+                        sum(click_shopwindow) click_shopwindow,
+                        sum(click_website)click_website,
+                        sum(click_download) click_download,
+                        sum(click_call_dy)click_call_dy,
+                        sum(submit_certification_count) submit_certification_count,
+                        sum(approval_count) approval_count,
+                        sum(first_order_count)first_rental_order_count,
+                        sum(first_rental_order_count) first_order_count,
+                        sum(commute_first_pay_count)commute_first_pay_count
+                      FROM `media_api`.bytedance_ad_report_daily
+                      WHERE stat_datetime >= date_format(
+                      date_sub(({date_time}, INTERVAL {day_count} DAY),
+                      '%Y%m%d') and advertiser_id={account_id}
+                       GROUP BY
+                       advertiser_id,
+                       campaign_id,
+                       ad_id,
+                       ad_name
+                       ) report
                     LEFT JOIN (
                      SELECT
                       cua.account_id id,

+ 162 - 333
Apietl/bytedance_etl/Q4Task/AppBytedanceAdvertiserReportBusi.py

@@ -193,339 +193,168 @@ SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),
        report.first_order_count,
        report.commute_first_pay_count
 FROM (
-         SELECT advertiser_id                        account_id,
-                sum(cost)                            cost,
-                sum(`show`)                          `show`,
-                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-                sum(click)                           click,
-                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-                round(
-                        sum(click) / sum(`show`) * 100,
-                        3
-                    )                                ctr,
-                sum(`convert`)                       `convert`,
-                round(sum(cost) / sum(`convert`), 3) convert_cost,
-                round(
-                        sum(`convert`) / sum(click) * 100,
-                        3
-                    )                                convert_rate,
-                sum(deep_convert)                    deep_convert,
-                round(
-                        sum(cost) / sum(deep_convert),
-                        3
-                    )                                deep_convert_cost,
-                round(
-                        sum(deep_convert) / sum(`convert`) * 100,
-                        3
-                    )                                deep_convert_rate,
-                sum(attribution_convert)             attribution_convert,
-                round(
-                        sum(cost) / sum(attribution_convert),
-                        3
-                    )                                attribution_convert_cost,
-                sum(attribution_deep_convert)        attribution_deep_convert,
-                round(
-                        sum(cost) / sum(attribution_deep_convert),
-                        3
-                    )                                attribution_deep_convert_cost,
-                sum(download_start)                  download_start,
-                round(
-                        sum(cost) / sum(download_start),
-                        3
-                    )                                download_start_cost,
-                round(
-                        sum(download_start) / sum(click),
-                        3
-                    )                                download_start_rate,
-                sum(download_finish)                 download_finish,
-                round(
-                        sum(cost) / sum(download_finish),
-                        3
-                    )                                download_finish_cost,
-                round(
-                        sum(download_finish) / sum(download_start) * 100,
-                        3
-                    )                                download_finish_rate,
-                sum(click_install)                   click_install,
-                sum(install_finish)                  install_finish,
-                round(
-                        sum(cost) / sum(install_finish),
-                        3
-                    )                                install_finish_cost,
-                round(
-                        sum(install_finish) / sum(download_finish) * 100,
-                        3
-                    )                                install_finish_rate,
-                sum(active)                          active,
-                round(sum(cost) / sum(active), 3)    active_cost,
-                round(
-                        sum(active) / sum(click) * 100,
-                        3
-                    )                                active_rate,
-                sum(register)                        register,
-                round(sum(cost) / sum(register), 3)  active_register_cost,
-                round(
-                        sum(active_register_rate) /{day_count} * 100,
-                        3
-                    )                                active_register_rate,
-                sum(next_day_open)                   next_day_open,
-                round(
-                        sum(cost) / sum(next_day_open),
-                        3
-                    )                                next_day_open_cost,
-                round(
-                        sum(next_day_open) / sum(active) * 100,
-                        3
-                    )                                next_day_open_rate,
-                sum(
-                        attribution_next_day_open_cnt
-                    )                                attribution_next_day_open_cnt,
-                round(
-                            sum(cost) / sum(
-                                attribution_next_day_open_cnt
-                            ),
-                            3
-                    )                                attribution_next_day_open_cost,
-                round(
-                                sum(
-                                        attribution_next_day_open_cnt
-                                    ) / sum(active) * 100,
-                                3
-                    )                                attribution_next_day_open_rate,
-                sum(game_addiction)                  game_addiction,
-                round(
-                        sum(cost) / sum(game_addiction),
-                        3
-                    )                                game_addiction_cost,
-                round(
-                        sum(game_addiction_rate) /{day_count} * 100,
-                        3
-                    )                                game_addiction_rate,
-                sum(pay_count)                       pay_count,
-                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-                round(
-                        sum(pay_count) / sum(active) * 100,
-                        3
-                    )                                active_pay_rate,
-                sum(loan_completion)                 loan_completion,
-                round(
-                        sum(cost) / sum(loan_completion),
-                        3
-                    )                                loan_completion_cost,
-                round(
-                        sum(loan_completion) / sum(register) * 100,
-                        3
-                    )                                loan_completion_rate,
-                round(sum(pre_loan_credit), 3)       pre_loan_credit,
-                round(
-                        sum(cost) / sum(pre_loan_credit),
-                        3
-                    )                                pre_loan_credit_cost,
-                sum(loan_credit)                     loan_credit,
-                round(
-                        sum(cost) / sum(loan_credit),
-                        3
-                    )                                loan_credit_cost,
-                round(
-                        sum(loan_credit) / sum(loan_completion) * 100,
-                        3
-                    )                                loan_credit_rate,
-                sum(in_app_uv)                       in_app_uv,
-                sum(in_app_detail_uv)                in_app_detail_uv,
-                sum(in_app_cart)                     in_app_cart,
-                sum(in_app_pay)                      in_app_pay,
-                sum(in_app_order)                    in_app_order,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_count
-                                ) /{day_count},
-                            3
-                    )                                attribution_game_pay_7d_count,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_cost
-                                ) /{day_count},
-                            3
-                    )                                attribution_game_pay_7d_cost,
-                round(
-                            sum(
-                                    attribution_active_pay_7d_per_count
-                                ) /{day_count},
-                            3
-                    )                                attribution_active_pay_7d_per_count,
-                sum(game_pay_cost)                   game_pay_cost,
-                sum(game_pay_count)                  game_pay_count,
-                sum(phone)                           phone,
-                sum(form)                            form,
-                sum(map_search)                      map_search,
-                sum(button)                          button,
-                sum(`view`)                          `view`,
-                sum(download)                        download,
-                sum(qq)                              qq,
-                sum(lottery)                         lottery,
-                sum(vote)                            vote,
-                sum(message)                         message,
-                sum(redirect)                        redirect,
-                sum(shopping)                        shopping,
-                sum(consult)                         consult,
-                sum(wechat)                          wechat,
-                sum(phone_confirm)                   phone_confirm,
-                sum(phone_connect)                   phone_connect,
-                sum(consult_effective)               consult_effective,
-                sum(coupon)                          coupon,
-                sum(coupon_single_page)              coupon_single_page,
-                sum(redirect_to_shop)                redirect_to_shop,
-                sum(poi_collect)                     poi_collect,
-                sum(poi_address_click)               poi_address_click,
-                sum(luban_order_cnt)                 luban_order_cnt,
-                sum(luban_order_stat_amount)         luban_order_stat_amount,
-                sum(luban_order_roi)                 luban_order_roi,
-                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-                sum(
-                        live_watch_one_minute_count
-                    )                                live_watch_one_minute_count,
-                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-                sum(luban_live_share_cnt)            luban_live_share_cnt,
-                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-                sum(luban_live_gift_amount)          luban_live_gift_amount,
-                sum(
-                        luban_live_slidecart_click_cnt
-                    )                                luban_live_slidecart_click_cnt,
-                sum(
-                        luban_live_click_product_cnt
-                    )                                luban_live_click_product_cnt,
-                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-                sum(
-                        luban_live_pay_order_stat_cost
-                    )                                luban_live_pay_order_stat_cost,
-                sum(live_component_click_count)      live_component_click_count,
-                round(
-                        sum(cost) / sum(live_component_click_count),
-                        3
-                    )                                live_component_click_cost,
-                round(
-                        sum(live_component_click_count) /{day_count} * 100,
-                        3
-                    )                                live_component_click_rate,
-                sum(wechat_login_count)              wechat_login_count,
-                sum(
-                        attribution_wechat_login_30d_count
-                    )                                attribution_wechat_login_30d_count,
-                round(
-                        sum(cost) / sum(wechat_login_count),
-                        3
-                    )                                wechat_login_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_login_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_login_30d_cost,
-                sum(wechat_first_pay_count)          wechat_first_pay_count,
-                sum(
-                        attribution_wechat_first_pay_30d_count
-                    )                                attribution_wechat_first_pay_30d_count,
-                round(
-                        sum(cost) / sum(wechat_first_pay_count),
-                        3
-                    )                                wechat_first_pay_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_first_pay_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_first_pay_30d_cost,
-                round(
-                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-                        3
-                    )                                wechat_first_pay_rate,
-                round(
-                                sum(
-                                        attribution_wechat_first_pay_30d_count
-                                    ) / sum(
-                                        attribution_wechat_login_30d_count
-                                    ) * 100,
-                                3
-                    )                                attribution_wechat_first_pay_30d_rate,
-                sum(wechat_pay_amount)               wechat_pay_amount,
-                sum(
-                        attribution_wechat_pay_30d_amount
-                    )                                attribution_wechat_pay_30d_amount,
-                sum(
-                        attribution_wechat_pay_30d_roi
-                    )                                attribution_wechat_pay_30d_roi,
-                sum(phone_effective)                 phone_effective,
-                sum(total_play)                      total_play,
-                sum(valid_play)                      valid_play,
-                round(
-                        sum(cost) / sum(valid_play),
-                        3
-                    )                                valid_play_cost,
-                round(
-                        sum(valid_play) / sum(`show`) * 100,
-                        3
-                    )                                valid_play_rate,
-                sum(play_25_feed_break)              play_25_feed_break,
-                sum(play_50_feed_break)              play_50_feed_break,
-                sum(play_75_feed_break)              play_75_feed_break,
-                sum(play_100_feed_break)             play_100_feed_break,
-                round(
-                        sum(average_play_time_per_play) /{day_count},
-                        3
-                    )                                average_play_time_per_play,
-                round(
-                        sum(play_over_rate) /{day_count} * 100,
-                        3
-                    )                                play_over_rate,
-                round(
-                        sum(wifi_play) / sum(total_play) * 100,
-                        3
-                    )                                wifi_play_rate,
-                sum(wifi_play)                       wifi_play,
-                round(sum(play_duration_sum) /{day_count}, 3) play_duration_sum,
-                sum(
-                        advanced_creative_phone_click
-                    )                                advanced_creative_phone_click,
-                sum(
-                        advanced_creative_counsel_click
-                    )                                advanced_creative_counsel_click,
-                sum(
-                        advanced_creative_form_click
-                    )                                advanced_creative_form_click,
-                sum(
-                        advanced_creative_coupon_addition
-                    )                                advanced_creative_coupon_addition,
-                sum(
-                        advanced_creative_form_submit
-                    )                                advanced_creative_form_submit,
-                sum(card_show)                       card_show,
-                sum(`share`)                         `share`,
-                sum(`comment`)                       `comment`,
-                sum(`like`)                          `like`,
-                sum(follow)                          follow,
-                sum(home_visited)                    home_visited,
-                sum(ies_challenge_click)             ies_challenge_click,
-                sum(ies_music_click)                 ies_music_click,
-                sum(location_click)                  location_click,
-                sum(message_action)                  message_action,
-                sum(click_landing_page)              click_landing_page,
-                sum(click_shopwindow)                click_shopwindow,
-                sum(click_website)                   click_website,
-                sum(click_download)                  click_download,
-                sum(click_call_dy)                   click_call_dy,
-                sum(submit_certification_count)      submit_certification_count,
-                sum(approval_count)                  approval_count,
-                sum(first_order_count)               first_rental_order_count,
-                sum(first_rental_order_count)        first_order_count,
-                sum(commute_first_pay_count)         commute_first_pay_count
-         FROM `media_api`.bytedance_advertiser_report_daily
-         WHERE stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),
-                 '%Y%m%d'
-             )
-         GROUP BY advertiser_id
+       SELECT 
+               advertiser_id account_id,
+               sum(cost) cost,
+               sum(`show`) `show`,
+               ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+               sum(click)click,
+               ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+               ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+               sum(`convert`)`convert`,
+               ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+               ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+               sum(deep_convert) deep_convert,
+               ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+               ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+               sum(attribution_convert)attribution_convert,
+               ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+               sum(attribution_deep_convert) attribution_deep_convert,
+               ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+               sum(download_start) download_start,
+               ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+               ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+               sum(download_finish) download_finish,
+               ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+               ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+               sum(click_install)click_install,
+               sum(install_finish) install_finish,
+               ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+               ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+               sum(active) active,
+               ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+               ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+               sum(register)register,
+               ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+               ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+               sum(next_day_open)next_day_open,
+               ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+               ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+               sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+               ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+               ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+               sum(game_addiction) game_addiction,
+               ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+               ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+               sum(pay_count)pay_count,
+               ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+               ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+               sum(loan_completion) loan_completion,
+               ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+               ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+               ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+               ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+               sum(loan_credit)loan_credit,
+               ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+               ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+               sum(in_app_uv)in_app_uv,
+               sum(in_app_detail_uv) in_app_detail_uv,
+               sum(in_app_cart) in_app_cart,
+               sum(in_app_pay) in_app_pay,
+               sum(in_app_order) in_app_order,
+               ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+               ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+               ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+               sum(game_pay_cost)game_pay_cost,
+               sum(game_pay_count) game_pay_count,
+               sum(phone) phone,
+               sum(form) form,
+               sum(map_search) map_search,
+               sum(button) button,
+               sum(`view`) `view`,
+               sum(download)download,
+               sum(qq)qq,
+               sum(lottery)lottery,
+               sum(vote) vote,
+               sum(message)message,
+               sum(redirect)redirect,
+               sum(shopping)shopping,
+               sum(consult)consult,
+               sum(wechat) wechat,
+               sum(phone_confirm)phone_confirm,
+               sum(phone_connect)phone_connect,
+               sum(consult_effective)consult_effective,
+               sum(coupon) coupon,
+               sum(coupon_single_page) coupon_single_page,
+               sum(redirect_to_shop) redirect_to_shop,
+               sum(poi_collect)poi_collect,
+               sum(poi_address_click)poi_address_click,
+               sum(luban_order_cnt) luban_order_cnt,
+               sum(luban_order_stat_amount)luban_order_stat_amount,
+               sum(luban_order_roi) luban_order_roi,
+               sum(luban_live_enter_cnt) luban_live_enter_cnt,
+               sum(live_watch_one_minute_count) live_watch_one_minute_count,
+               sum(luban_live_follow_cnt) luban_live_follow_cnt,
+               sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+               sum(luban_live_comment_cnt) luban_live_comment_cnt,
+               sum(luban_live_share_cnt) luban_live_share_cnt,
+               sum(luban_live_gift_cnt)luban_live_gift_cnt,
+               sum(luban_live_gift_amount) luban_live_gift_amount,
+               sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+               sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+               sum(luban_live_pay_order_count) luban_live_pay_order_count,
+               sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+               sum(live_component_click_count) live_component_click_count,
+               ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+               ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+               sum(wechat_login_count) wechat_login_count,
+               sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+               sum(wechat_first_pay_count) wechat_first_pay_count,
+               sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+               ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+               ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+               sum(wechat_pay_amount)wechat_pay_amount,
+               sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+               sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+               sum(phone_effective) phone_effective,
+               sum(total_play) total_play,
+               sum(valid_play) valid_play,
+               ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+               ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+               sum(play_25_feed_break) play_25_feed_break,
+               sum(play_50_feed_break) play_50_feed_break,
+               sum(play_75_feed_break) play_75_feed_break,
+               sum(play_100_feed_break)play_100_feed_break,
+               ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+               ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+               ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+               sum(wifi_play)wifi_play,
+               ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+               sum(advanced_creative_phone_click) advanced_creative_phone_click,
+               sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+               sum(advanced_creative_form_click) advanced_creative_form_click,
+               sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+               sum(advanced_creative_form_submit) advanced_creative_form_submit,
+               sum(card_show)card_show,
+               sum(`share`)`share`,
+               sum(`comment`)`comment`,
+               sum(`like`) `like`,
+               sum(follow) follow,
+               sum(home_visited) home_visited,
+               sum(ies_challenge_click)ies_challenge_click,
+               sum(ies_music_click) ies_music_click,
+               sum(location_click) location_click,
+               sum(message_action) message_action,
+               sum(click_landing_page) click_landing_page,
+               sum(click_shopwindow) click_shopwindow,
+               sum(click_website)click_website,
+               sum(click_download) click_download,
+               sum(click_call_dy)click_call_dy,
+               sum(submit_certification_count) submit_certification_count,
+               sum(approval_count) approval_count,
+               sum(first_order_count)first_rental_order_count,
+               sum(first_rental_order_count) first_order_count,
+               sum(commute_first_pay_count)commute_first_pay_count
+              FROM `media_api`.bytedance_advertiser_report_daily
+              WHERE stat_datetime >= date_format(
+              date_sub(({date_time}, INTERVAL {day_count} - 1 DAY),
+              '%Y%m%d'
+              )
+              GROUP BY advertiser_id
      ) report
          LEFT JOIN (
     SELECT cua.account_id  id,

+ 162 - 333
Apietl/bytedance_etl/Q4Task/AppBytedanceAdvertiserReportBusiMonth.py

@@ -193,339 +193,168 @@ SELECT date_format({date_time},'%Y%m') as stat_mon,
        report.first_order_count,
        report.commute_first_pay_count
 FROM (
-         SELECT advertiser_id                        account_id,
-                sum(cost)                            cost,
-                sum(`show`)                          `show`,
-                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-                sum(click)                           click,
-                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-                round(
-                        sum(click) / sum(`show`) * 100,
-                        3
-                    )                                ctr,
-                sum(`convert`)                       `convert`,
-                round(sum(cost) / sum(`convert`), 3) convert_cost,
-                round(
-                        sum(`convert`) / sum(click) * 100,
-                        3
-                    )                                convert_rate,
-                sum(deep_convert)                    deep_convert,
-                round(
-                        sum(cost) / sum(deep_convert),
-                        3
-                    )                                deep_convert_cost,
-                round(
-                        sum(deep_convert) / sum(`convert`) * 100,
-                        3
-                    )                                deep_convert_rate,
-                sum(attribution_convert)             attribution_convert,
-                round(
-                        sum(cost) / sum(attribution_convert),
-                        3
-                    )                                attribution_convert_cost,
-                sum(attribution_deep_convert)        attribution_deep_convert,
-                round(
-                        sum(cost) / sum(attribution_deep_convert),
-                        3
-                    )                                attribution_deep_convert_cost,
-                sum(download_start)                  download_start,
-                round(
-                        sum(cost) / sum(download_start),
-                        3
-                    )                                download_start_cost,
-                round(
-                        sum(download_start) / sum(click),
-                        3
-                    )                                download_start_rate,
-                sum(download_finish)                 download_finish,
-                round(
-                        sum(cost) / sum(download_finish),
-                        3
-                    )                                download_finish_cost,
-                round(
-                        sum(download_finish) / sum(download_start) * 100,
-                        3
-                    )                                download_finish_rate,
-                sum(click_install)                   click_install,
-                sum(install_finish)                  install_finish,
-                round(
-                        sum(cost) / sum(install_finish),
-                        3
-                    )                                install_finish_cost,
-                round(
-                        sum(install_finish) / sum(download_finish) * 100,
-                        3
-                    )                                install_finish_rate,
-                sum(active)                          active,
-                round(sum(cost) / sum(active), 3)    active_cost,
-                round(
-                        sum(active) / sum(click) * 100,
-                        3
-                    )                                active_rate,
-                sum(register)                        register,
-                round(sum(cost) / sum(register), 3)  active_register_cost,
-                round(
-                        sum(active_register_rate) /{day_count} * 100,
-                        3
-                    )                                active_register_rate,
-                sum(next_day_open)                   next_day_open,
-                round(
-                        sum(cost) / sum(next_day_open),
-                        3
-                    )                                next_day_open_cost,
-                round(
-                        sum(next_day_open) / sum(active) * 100,
-                        3
-                    )                                next_day_open_rate,
-                sum(
-                        attribution_next_day_open_cnt
-                    )                                attribution_next_day_open_cnt,
-                round(
-                            sum(cost) / sum(
-                                attribution_next_day_open_cnt
-                            ),
-                            3
-                    )                                attribution_next_day_open_cost,
-                round(
-                                sum(
-                                        attribution_next_day_open_cnt
-                                    ) / sum(active) * 100,
-                                3
-                    )                                attribution_next_day_open_rate,
-                sum(game_addiction)                  game_addiction,
-                round(
-                        sum(cost) / sum(game_addiction),
-                        3
-                    )                                game_addiction_cost,
-                round(
-                        sum(game_addiction_rate) /{day_count} * 100,
-                        3
-                    )                                game_addiction_rate,
-                sum(pay_count)                       pay_count,
-                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-                round(
-                        sum(pay_count) / sum(active) * 100,
-                        3
-                    )                                active_pay_rate,
-                sum(loan_completion)                 loan_completion,
-                round(
-                        sum(cost) / sum(loan_completion),
-                        3
-                    )                                loan_completion_cost,
-                round(
-                        sum(loan_completion) / sum(register) * 100,
-                        3
-                    )                                loan_completion_rate,
-                round(sum(pre_loan_credit), 3)       pre_loan_credit,
-                round(
-                        sum(cost) / sum(pre_loan_credit),
-                        3
-                    )                                pre_loan_credit_cost,
-                sum(loan_credit)                     loan_credit,
-                round(
-                        sum(cost) / sum(loan_credit),
-                        3
-                    )                                loan_credit_cost,
-                round(
-                        sum(loan_credit) / sum(loan_completion) * 100,
-                        3
-                    )                                loan_credit_rate,
-                sum(in_app_uv)                       in_app_uv,
-                sum(in_app_detail_uv)                in_app_detail_uv,
-                sum(in_app_cart)                     in_app_cart,
-                sum(in_app_pay)                      in_app_pay,
-                sum(in_app_order)                    in_app_order,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_count
-                                ) /{day_count},
-                            3
-                    )                                attribution_game_pay_7d_count,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_cost
-                                ) /{day_count},
-                            3
-                    )                                attribution_game_pay_7d_cost,
-                round(
-                            sum(
-                                    attribution_active_pay_7d_per_count
-                                ) /{day_count},
-                            3
-                    )                                attribution_active_pay_7d_per_count,
-                sum(game_pay_cost)                   game_pay_cost,
-                sum(game_pay_count)                  game_pay_count,
-                sum(phone)                           phone,
-                sum(form)                            form,
-                sum(map_search)                      map_search,
-                sum(button)                          button,
-                sum(`view`)                          `view`,
-                sum(download)                        download,
-                sum(qq)                              qq,
-                sum(lottery)                         lottery,
-                sum(vote)                            vote,
-                sum(message)                         message,
-                sum(redirect)                        redirect,
-                sum(shopping)                        shopping,
-                sum(consult)                         consult,
-                sum(wechat)                          wechat,
-                sum(phone_confirm)                   phone_confirm,
-                sum(phone_connect)                   phone_connect,
-                sum(consult_effective)               consult_effective,
-                sum(coupon)                          coupon,
-                sum(coupon_single_page)              coupon_single_page,
-                sum(redirect_to_shop)                redirect_to_shop,
-                sum(poi_collect)                     poi_collect,
-                sum(poi_address_click)               poi_address_click,
-                sum(luban_order_cnt)                 luban_order_cnt,
-                sum(luban_order_stat_amount)         luban_order_stat_amount,
-                sum(luban_order_roi)                 luban_order_roi,
-                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-                sum(
-                        live_watch_one_minute_count
-                    )                                live_watch_one_minute_count,
-                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-                sum(luban_live_share_cnt)            luban_live_share_cnt,
-                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-                sum(luban_live_gift_amount)          luban_live_gift_amount,
-                sum(
-                        luban_live_slidecart_click_cnt
-                    )                                luban_live_slidecart_click_cnt,
-                sum(
-                        luban_live_click_product_cnt
-                    )                                luban_live_click_product_cnt,
-                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-                sum(
-                        luban_live_pay_order_stat_cost
-                    )                                luban_live_pay_order_stat_cost,
-                sum(live_component_click_count)      live_component_click_count,
-                round(
-                        sum(cost) / sum(live_component_click_count),
-                        3
-                    )                                live_component_click_cost,
-                round(
-                        sum(live_component_click_count) /{day_count} * 100,
-                        3
-                    )                                live_component_click_rate,
-                sum(wechat_login_count)              wechat_login_count,
-                sum(
-                        attribution_wechat_login_30d_count
-                    )                                attribution_wechat_login_30d_count,
-                round(
-                        sum(cost) / sum(wechat_login_count),
-                        3
-                    )                                wechat_login_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_login_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_login_30d_cost,
-                sum(wechat_first_pay_count)          wechat_first_pay_count,
-                sum(
-                        attribution_wechat_first_pay_30d_count
-                    )                                attribution_wechat_first_pay_30d_count,
-                round(
-                        sum(cost) / sum(wechat_first_pay_count),
-                        3
-                    )                                wechat_first_pay_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_first_pay_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_first_pay_30d_cost,
-                round(
-                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-                        3
-                    )                                wechat_first_pay_rate,
-                round(
-                                sum(
-                                        attribution_wechat_first_pay_30d_count
-                                    ) / sum(
-                                        attribution_wechat_login_30d_count
-                                    ) * 100,
-                                3
-                    )                                attribution_wechat_first_pay_30d_rate,
-                sum(wechat_pay_amount)               wechat_pay_amount,
-                sum(
-                        attribution_wechat_pay_30d_amount
-                    )                                attribution_wechat_pay_30d_amount,
-                sum(
-                        attribution_wechat_pay_30d_roi
-                    )                                attribution_wechat_pay_30d_roi,
-                sum(phone_effective)                 phone_effective,
-                sum(total_play)                      total_play,
-                sum(valid_play)                      valid_play,
-                round(
-                        sum(cost) / sum(valid_play),
-                        3
-                    )                                valid_play_cost,
-                round(
-                        sum(valid_play) / sum(`show`) * 100,
-                        3
-                    )                                valid_play_rate,
-                sum(play_25_feed_break)              play_25_feed_break,
-                sum(play_50_feed_break)              play_50_feed_break,
-                sum(play_75_feed_break)              play_75_feed_break,
-                sum(play_100_feed_break)             play_100_feed_break,
-                round(
-                        sum(average_play_time_per_play) /{day_count},
-                        3
-                    )                                average_play_time_per_play,
-                round(
-                        sum(play_over_rate) /{day_count} * 100,
-                        3
-                    )                                play_over_rate,
-                round(
-                        sum(wifi_play) / sum(total_play) * 100,
-                        3
-                    )                                wifi_play_rate,
-                sum(wifi_play)                       wifi_play,
-                round(sum(play_duration_sum) /{day_count}, 3) play_duration_sum,
-                sum(
-                        advanced_creative_phone_click
-                    )                                advanced_creative_phone_click,
-                sum(
-                        advanced_creative_counsel_click
-                    )                                advanced_creative_counsel_click,
-                sum(
-                        advanced_creative_form_click
-                    )                                advanced_creative_form_click,
-                sum(
-                        advanced_creative_coupon_addition
-                    )                                advanced_creative_coupon_addition,
-                sum(
-                        advanced_creative_form_submit
-                    )                                advanced_creative_form_submit,
-                sum(card_show)                       card_show,
-                sum(`share`)                         `share`,
-                sum(`comment`)                       `comment`,
-                sum(`like`)                          `like`,
-                sum(follow)                          follow,
-                sum(home_visited)                    home_visited,
-                sum(ies_challenge_click)             ies_challenge_click,
-                sum(ies_music_click)                 ies_music_click,
-                sum(location_click)                  location_click,
-                sum(message_action)                  message_action,
-                sum(click_landing_page)              click_landing_page,
-                sum(click_shopwindow)                click_shopwindow,
-                sum(click_website)                   click_website,
-                sum(click_download)                  click_download,
-                sum(click_call_dy)                   click_call_dy,
-                sum(submit_certification_count)      submit_certification_count,
-                sum(approval_count)                  approval_count,
-                sum(first_order_count)               first_rental_order_count,
-                sum(first_rental_order_count)        first_order_count,
-                sum(commute_first_pay_count)         commute_first_pay_count
-         FROM `media_api`.bytedance_advertiser_report_daily
-         WHERE stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL {day_count}  DAY),
-                 '%Y%m%d'
-             )
-         GROUP BY advertiser_id
+      SELECT 
+               advertiser_id account_id,
+               sum(cost) cost,
+               sum(`show`) `show`,
+               ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+               sum(click)click,
+               ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+               ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+               sum(`convert`)`convert`,
+               ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+               ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+               sum(deep_convert) deep_convert,
+               ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+               ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+               sum(attribution_convert)attribution_convert,
+               ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+               sum(attribution_deep_convert) attribution_deep_convert,
+               ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+               sum(download_start) download_start,
+               ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+               ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+               sum(download_finish) download_finish,
+               ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+               ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+               sum(click_install)click_install,
+               sum(install_finish) install_finish,
+               ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+               ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+               sum(active) active,
+               ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+               ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+               sum(register)register,
+               ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+               ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+               sum(next_day_open)next_day_open,
+               ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+               ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+               sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+               ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+               ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+               sum(game_addiction) game_addiction,
+               ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+               ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+               sum(pay_count)pay_count,
+               ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+               ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+               sum(loan_completion) loan_completion,
+               ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+               ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+               ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+               ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+               sum(loan_credit)loan_credit,
+               ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+               ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+               sum(in_app_uv)in_app_uv,
+               sum(in_app_detail_uv) in_app_detail_uv,
+               sum(in_app_cart)in_app_cart,
+               sum(in_app_pay) in_app_pay,
+               sum(in_app_order) in_app_order,
+               ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+               ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+               ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+               sum(game_pay_cost)game_pay_cost,
+               sum(game_pay_count) game_pay_count,
+               sum(phone)phone,
+               sum(form) form,
+               sum(map_search) map_search,
+               sum(button) button,
+               sum(`view`) `view`,
+               sum(download)download,
+               sum(qq)qq,
+               sum(lottery)lottery,
+               sum(vote) vote,
+               sum(message)message,
+               sum(redirect)redirect,
+               sum(shopping)shopping,
+               sum(consult)consult,
+               sum(wechat) wechat,
+               sum(phone_confirm)phone_confirm,
+               sum(phone_connect)phone_connect,
+               sum(consult_effective)consult_effective,
+               sum(coupon) coupon,
+               sum(coupon_single_page) coupon_single_page,
+               sum(redirect_to_shop) redirect_to_shop,
+               sum(poi_collect)poi_collect,
+               sum(poi_address_click)poi_address_click,
+               sum(luban_order_cnt) luban_order_cnt,
+               sum(luban_order_stat_amount)luban_order_stat_amount,
+               sum(luban_order_roi) luban_order_roi,
+               sum(luban_live_enter_cnt) luban_live_enter_cnt,
+               sum(live_watch_one_minute_count) live_watch_one_minute_count,
+               sum(luban_live_follow_cnt) luban_live_follow_cnt,
+               sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+               sum(luban_live_comment_cnt) luban_live_comment_cnt,
+               sum(luban_live_share_cnt) luban_live_share_cnt,
+               sum(luban_live_gift_cnt)luban_live_gift_cnt,
+               sum(luban_live_gift_amount) luban_live_gift_amount,
+               sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+               sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+               sum(luban_live_pay_order_count) luban_live_pay_order_count,
+               sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+               sum(live_component_click_count) live_component_click_count,
+               ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+               ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+               sum(wechat_login_count) wechat_login_count,
+               sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+               sum(wechat_first_pay_count) wechat_first_pay_count,
+               sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+               ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+               ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+               sum(wechat_pay_amount)wechat_pay_amount,
+               sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+               sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+               sum(phone_effective) phone_effective,
+               sum(total_play) total_play,
+               sum(valid_play) valid_play,
+               ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+               ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+               sum(play_25_feed_break) play_25_feed_break,
+               sum(play_50_feed_break) play_50_feed_break,
+               sum(play_75_feed_break) play_75_feed_break,
+               sum(play_100_feed_break)play_100_feed_break,
+               ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+               ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+               ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+               sum(wifi_play)wifi_play,
+               ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+               sum(advanced_creative_phone_click) advanced_creative_phone_click,
+               sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+               sum(advanced_creative_form_click) advanced_creative_form_click,
+               sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+               sum(advanced_creative_form_submit) advanced_creative_form_submit,
+               sum(card_show)card_show,
+               sum(`share`)`share`,
+               sum(`comment`)`comment`,
+               sum(`like`) `like`,
+               sum(follow) follow,
+               sum(home_visited) home_visited,
+               sum(ies_challenge_click)ies_challenge_click,
+               sum(ies_music_click) ies_music_click,
+               sum(location_click) location_click,
+               sum(message_action) message_action,
+               sum(click_landing_page) click_landing_page,
+               sum(click_shopwindow) click_shopwindow,
+               sum(click_website)click_website,
+               sum(click_download) click_download,
+               sum(click_call_dy)click_call_dy,
+               sum(submit_certification_count) submit_certification_count,
+               sum(approval_count) approval_count,
+               sum(first_order_count)first_rental_order_count,
+               sum(first_rental_order_count) first_order_count,
+               sum(commute_first_pay_count)commute_first_pay_count
+              FROM `media_api`.bytedance_advertiser_report_daily
+              WHERE stat_datetime >= date_format(
+              date_sub(({date_time}, INTERVAL {day_count} DAY),
+              '%Y%m%d'
+              )
+              GROUP BY advertiser_id
      ) report
          LEFT JOIN (
     SELECT cua.account_id  id,

+ 165 - 342
Apietl/bytedance_etl/Q4Task/AppBytedanceCampaignReportBusi.py

@@ -195,348 +195,171 @@ report.account_id,
  report.commute_first_pay_count
 FROM
  (
-  SELECT
-   advertiser_id account_id,
-   campaign_id campaign_id,
-   campaign_name campaign_name,
-   sum(cost) cost,
-   sum(`show`) `show`,
-   round(sum(cost) / sum(`show`), 3) avg_show_cost,
-   sum(click) click,
-   round(sum(cost) / sum(`click`), 3) avg_click_cost,
-   round(
-    sum(click) / sum(`show`) * 100,
-    3
-   ) ctr,
-   sum(`convert`) `convert`,
-   round(sum(cost) / sum(`convert`), 3) convert_cost,
-   round(
-    sum(`convert`) / sum(click) * 100,
-    3
-   ) convert_rate,
-   sum(deep_convert) deep_convert,
-   round(
-    sum(cost) / sum(deep_convert),
-    3
-   ) deep_convert_cost,
-   round(
-    sum(deep_convert) / sum(`convert`) * 100,
-    3
-   ) deep_convert_rate,
-   sum(attribution_convert) attribution_convert,
-   round(
-    sum(cost) / sum(attribution_convert),
-    3
-   ) attribution_convert_cost,
-   sum(attribution_deep_convert) attribution_deep_convert,
-   round(
-    sum(cost) / sum(attribution_deep_convert),
-    3
-   ) attribution_deep_convert_cost,
-   sum(download_start) download_start,
-   round(
-    sum(cost) / sum(download_start),
-    3
-   ) download_start_cost,
-   round(
-    sum(download_start) / sum(click),
-    3
-   ) download_start_rate,
-   sum(download_finish) download_finish,
-   round(
-    sum(cost) / sum(download_finish),
-    3
-   ) download_finish_cost,
-   round(
-    sum(download_finish) / sum(download_start) * 100,
-    3
-   ) download_finish_rate,
-   sum(click_install) click_install,
-   sum(install_finish) install_finish,
-   round(
-    sum(cost) / sum(install_finish),
-    3
-   ) install_finish_cost,
-   round(
-    sum(install_finish) / sum(download_finish) * 100,
-    3
-   ) install_finish_rate,
-   sum(active) active,
-   round(sum(cost) / sum(active), 3) active_cost,
-   round(
-    sum(active) / sum(click) * 100,
-    3
-   ) active_rate,
-   sum(register) register,
-   round(sum(cost) / sum(register), 3) active_register_cost,
-   round(
-    sum(active_register_rate) / {day_count} * 100,
-    3
-   ) active_register_rate,
-   sum(next_day_open) next_day_open,
-   round(
-    sum(cost) / sum(next_day_open),
-    3
-   ) next_day_open_cost,
-   round(
-    sum(next_day_open) / sum(active) * 100,
-    3
-   ) next_day_open_rate,
-   sum(
-    attribution_next_day_open_cnt
-   ) attribution_next_day_open_cnt,
-   round(
-    sum(cost) / sum(
-     attribution_next_day_open_cnt
-    ),
-    3
-   ) attribution_next_day_open_cost,
-   round(
-    sum(
-     attribution_next_day_open_cnt
-    ) / sum(active) * 100,
-    3
-   ) attribution_next_day_open_rate,
-   sum(game_addiction) game_addiction,
-   round(
-    sum(cost) / sum(game_addiction),
-    3
-   ) game_addiction_cost,
-   round(
-    sum(game_addiction_rate) / {day_count} * 100,
-    3
-   ) game_addiction_rate,
-   sum(pay_count) pay_count,
-   round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-   round(
-    sum(pay_count) / sum(active) * 100,
-    3
-   ) active_pay_rate,
-   sum(loan_completion) loan_completion,
-   round(
-    sum(cost) / sum(loan_completion),
-    3
-   ) loan_completion_cost,
-   round(
-    sum(loan_completion) / sum(register) * 100,
-    3
-   ) loan_completion_rate,
-   round(sum(pre_loan_credit), 3) pre_loan_credit,
-   round(
-    sum(cost) / sum(pre_loan_credit),
-    3
-   ) pre_loan_credit_cost,
-   sum(loan_credit) loan_credit,
-   round(
-    sum(cost) / sum(loan_credit),
-    3
-   ) loan_credit_cost,
-   round(
-    sum(loan_credit) / sum(loan_completion) * 100,
-    3
-   ) loan_credit_rate,
-   sum(in_app_uv) in_app_uv,
-   sum(in_app_detail_uv) in_app_detail_uv,
-   sum(in_app_cart) in_app_cart,
-   sum(in_app_pay) in_app_pay,
-   sum(in_app_order) in_app_order,
-   round(
-    sum(
-     attribution_game_pay_7d_count
-    ) / {day_count},
-    3
-   ) attribution_game_pay_7d_count,
-   round(
-    sum(
-     attribution_game_pay_7d_cost
-    ) / {day_count},
-    3
-   ) attribution_game_pay_7d_cost,
-   round(
-    sum(
-     attribution_active_pay_7d_per_count
-    ) / {day_count},
-    3
-   ) attribution_active_pay_7d_per_count,
-   sum(game_pay_cost) game_pay_cost,
-   sum(game_pay_count) game_pay_count,
-   sum(phone) phone,
-   sum(form) form,
-   sum(map_search) map_search,
-   sum(button) button,
-   sum(`view`) `view`,
-   sum(download) download,
-   sum(qq) qq,
-   sum(lottery) lottery,
-   sum(vote) vote,
-   sum(message) message,
-   sum(redirect) redirect,
-   sum(shopping) shopping,
-   sum(consult) consult,
-   sum(wechat) wechat,
-   sum(phone_confirm) phone_confirm,
-   sum(phone_connect) phone_connect,
-   sum(consult_effective) consult_effective,
-   sum(coupon) coupon,
-   sum(coupon_single_page) coupon_single_page,
-   sum(redirect_to_shop) redirect_to_shop,
-   sum(poi_collect) poi_collect,
-   sum(poi_address_click) poi_address_click,
-   sum(luban_order_cnt) luban_order_cnt,
-   sum(luban_order_stat_amount) luban_order_stat_amount,
-   sum(luban_order_roi) luban_order_roi,
-   sum(luban_live_enter_cnt) luban_live_enter_cnt,
-   sum(
-    live_watch_one_minute_count
-   ) live_watch_one_minute_count,
-   sum(luban_live_follow_cnt) luban_live_follow_cnt,
-   sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
-   sum(luban_live_comment_cnt) luban_live_comment_cnt,
-   sum(luban_live_share_cnt) luban_live_share_cnt,
-   sum(luban_live_gift_cnt) luban_live_gift_cnt,
-   sum(luban_live_gift_amount) luban_live_gift_amount,
-   sum(
-    luban_live_slidecart_click_cnt
-   ) luban_live_slidecart_click_cnt,
-   sum(
-    luban_live_click_product_cnt
-   ) luban_live_click_product_cnt,
-   sum(luban_live_pay_order_count) luban_live_pay_order_count,
-   sum(
-    luban_live_pay_order_stat_cost
-   ) luban_live_pay_order_stat_cost,
-   sum(live_component_click_count) live_component_click_count,
-   round(
-    sum(cost) / sum(live_component_click_count),
-    3
-   ) live_component_click_cost,
-   round(
-    sum(live_component_click_count) / {day_count} * 100,
-    3
-   ) live_component_click_rate,
-   sum(wechat_login_count) wechat_login_count,
-   sum(
-    attribution_wechat_login_30d_count
-   ) attribution_wechat_login_30d_count,
-   round(
-    sum(cost) / sum(wechat_login_count),
-    3
-   ) wechat_login_cost,
-   round(
-    sum(cost) / sum(
-     attribution_wechat_login_30d_count
-    ),
-    3
-   ) attribution_wechat_login_30d_cost,
-   sum(wechat_first_pay_count) wechat_first_pay_count,
-   sum(
-    attribution_wechat_first_pay_30d_count
-   ) attribution_wechat_first_pay_30d_count,
-   round(
-    sum(cost) / sum(wechat_first_pay_count),
-    3
-   ) wechat_first_pay_cost,
-   round(
-    sum(cost) / sum(
-     attribution_wechat_first_pay_30d_count
-    ),
-    3
-   ) attribution_wechat_first_pay_30d_cost,
-   round(
-    sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-    3
-   ) wechat_first_pay_rate,
-   round(
-    sum(
-     attribution_wechat_first_pay_30d_count
-    ) / sum(
-     attribution_wechat_login_30d_count
-    ) * 100,
-    3
-   ) attribution_wechat_first_pay_30d_rate,
-   sum(wechat_pay_amount) wechat_pay_amount,
-   sum(
-    attribution_wechat_pay_30d_amount
-   ) attribution_wechat_pay_30d_amount,
-   sum(
-    attribution_wechat_pay_30d_roi
-   ) attribution_wechat_pay_30d_roi,
-   sum(phone_effective) phone_effective,
-   sum(total_play) total_play,
-   sum(valid_play) valid_play,
-   round(
-    sum(cost) / sum(valid_play),
-    3
-   ) valid_play_cost,
-   round(
-    sum(valid_play) / sum(`show`) * 100,
-    3
-   ) valid_play_rate,
-   sum(play_25_feed_break) play_25_feed_break,
-   sum(play_50_feed_break) play_50_feed_break,
-   sum(play_75_feed_break) play_75_feed_break,
-   sum(play_100_feed_break) play_100_feed_break,
-   round(
-    sum(average_play_time_per_play) / {day_count},
-    3
-   ) average_play_time_per_play,
-   round(
-    sum(play_over_rate) / {day_count} * 100,
-    3
-   ) play_over_rate,
-   round(
-    sum(wifi_play) / sum(total_play) * 100,
-    3
-   ) wifi_play_rate,
-   sum(wifi_play) wifi_play,
-   round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-   sum(
-    advanced_creative_phone_click
-   ) advanced_creative_phone_click,
-   sum(
-    advanced_creative_counsel_click
-   ) advanced_creative_counsel_click,
-   sum(
-    advanced_creative_form_click
-   ) advanced_creative_form_click,
-   sum(
-    advanced_creative_coupon_addition
-   ) advanced_creative_coupon_addition,
-   sum(
-    advanced_creative_form_submit
-   ) advanced_creative_form_submit,
-   sum(card_show) card_show,
-   sum(`share`) `share`,
-   sum(`comment`) `comment`,
-   sum(`like`) `like`,
-   sum(follow) follow,
-   sum(home_visited) home_visited,
-   sum(ies_challenge_click) ies_challenge_click,
-   sum(ies_music_click) ies_music_click,
-   sum(location_click) location_click,
-   sum(message_action) message_action,
-   sum(click_landing_page) click_landing_page,
-   sum(click_shopwindow) click_shopwindow,
-   sum(click_website) click_website,
-   sum(click_download) click_download,
-   sum(click_call_dy) click_call_dy,
-   sum(submit_certification_count) submit_certification_count,
-   sum(approval_count) approval_count,
-   sum(first_order_count) first_rental_order_count,
-   sum(first_rental_order_count) first_order_count,
-   sum(commute_first_pay_count) commute_first_pay_count
-  FROM
-   `media_api`.bytedance_campaign_report_daily
-  WHERE
-   stat_datetime >= date_format(
-    date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),
-    '%Y%m%d'
-   )
-  GROUP BY
-   advertiser_id,
-   campaign_id,
-   campaign_name
- ) report
+             SELECT
+                        advertiser_id account_id,
+                        campaign_id campaign_id,
+                        campaign_name campaign_name,
+                        sum(cost) cost,
+                        sum(`show`) `show`,
+                        ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+                        sum(click)click,
+                        ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+                        ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+                        sum(`convert`)`convert`,
+                        ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+                        ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+                        sum(deep_convert) deep_convert,
+                        ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+                        ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+                        sum(attribution_convert)attribution_convert,
+                        ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+                        sum(attribution_deep_convert) attribution_deep_convert,
+                        ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+                        sum(download_start) download_start,
+                        ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+                        ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+                        sum(download_finish) download_finish,
+                        ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+                        ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+                        sum(click_install)click_install,
+                        sum(install_finish) install_finish,
+                        ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+                        ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+                        sum(active) active,
+                        ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+                        ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+                        sum(register)register,
+                        ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+                        ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+                        sum(next_day_open)next_day_open,
+                        ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+                        ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+                        sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+                        ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+                        ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+                        sum(game_addiction) game_addiction,
+                        ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+                        ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+                        sum(pay_count)pay_count,
+                        ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+                        ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+                        sum(loan_completion) loan_completion,
+                        ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+                        ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+                        ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+                        ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+                        sum(loan_credit)loan_credit,
+                        ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+                        ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+                        sum(in_app_uv)in_app_uv,
+                        sum(in_app_detail_uv) in_app_detail_uv,
+                        sum(in_app_cart)in_app_cart,
+                        sum(in_app_pay) in_app_pay,
+                        sum(in_app_order) in_app_order,
+                        ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+                        ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+                        ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+                        sum(game_pay_cost)game_pay_cost,
+                        sum(game_pay_count) game_pay_count,
+                        sum(phone)phone,
+                        sum(form) form,
+                        sum(map_search) map_search,
+                        sum(button) button,
+                        sum(`view`) `view`,
+                        sum(download)download,
+                        sum(qq)qq,
+                        sum(lottery)lottery,
+                        sum(vote) vote,
+                        sum(message)message,
+                        sum(redirect)redirect,
+                        sum(shopping)shopping,
+                        sum(consult)consult,
+                        sum(wechat) wechat,
+                        sum(phone_confirm)phone_confirm,
+                        sum(phone_connect)phone_connect,
+                        sum(consult_effective)consult_effective,
+                        sum(coupon) coupon,
+                        sum(coupon_single_page) coupon_single_page,
+                        sum(redirect_to_shop) redirect_to_shop,
+                        sum(poi_collect)poi_collect,
+                        sum(poi_address_click)poi_address_click,
+                        sum(luban_order_cnt) luban_order_cnt,
+                        sum(luban_order_stat_amount)luban_order_stat_amount,
+                        sum(luban_order_roi) luban_order_roi,
+                        sum(luban_live_enter_cnt) luban_live_enter_cnt,
+                        sum(live_watch_one_minute_count) live_watch_one_minute_count,
+                        sum(luban_live_follow_cnt) luban_live_follow_cnt,
+                        sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+                        sum(luban_live_comment_cnt) luban_live_comment_cnt,
+                        sum(luban_live_share_cnt) luban_live_share_cnt,
+                        sum(luban_live_gift_cnt)luban_live_gift_cnt,
+                        sum(luban_live_gift_amount) luban_live_gift_amount,
+                        sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+                        sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+                        sum(luban_live_pay_order_count) luban_live_pay_order_count,
+                        sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+                        sum(live_component_click_count) live_component_click_count,
+                        ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+                        ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+                        sum(wechat_login_count) wechat_login_count,
+                        sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+                        ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+                        ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+                        sum(wechat_first_pay_count) wechat_first_pay_count,
+                        sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+                        ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+                        ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+                        ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+                        ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+                        sum(wechat_pay_amount)wechat_pay_amount,
+                        sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+                        sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+                        sum(phone_effective) phone_effective,
+                        sum(total_play) total_play,
+                        sum(valid_play) valid_play,
+                        ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+                        ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+                        sum(play_25_feed_break) play_25_feed_break,
+                        sum(play_50_feed_break) play_50_feed_break,
+                        sum(play_75_feed_break) play_75_feed_break,
+                        sum(play_100_feed_break)play_100_feed_break,
+                        ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+                        ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+                        ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+                        sum(wifi_play)wifi_play,
+                        ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+                        sum(advanced_creative_phone_click) advanced_creative_phone_click,
+                        sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+                        sum(advanced_creative_form_click) advanced_creative_form_click,
+                        sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+                        sum(advanced_creative_form_submit) advanced_creative_form_submit,
+                        sum(card_show)card_show,
+                        sum(`share`)`share`,
+                        sum(`comment`)`comment`,
+                        sum(`like`) `like`,
+                        sum(follow) follow,
+                        sum(home_visited) home_visited,
+                        sum(ies_challenge_click)ies_challenge_click,
+                        sum(ies_music_click) ies_music_click,
+                        sum(location_click) location_click,
+                        sum(message_action) message_action,
+                        sum(click_landing_page) click_landing_page,
+                        sum(click_shopwindow) click_shopwindow,
+                        sum(click_website)click_website,
+                        sum(click_download) click_download,
+                        sum(click_call_dy)click_call_dy,
+                        sum(submit_certification_count) submit_certification_count,
+                        sum(approval_count) approval_count,
+                        sum(first_order_count)first_rental_order_count,
+                        sum(first_rental_order_count) first_order_count,
+                        sum(commute_first_pay_count)commute_first_pay_count
+                      FROM `media_api`.bytedance_campaign_report_daily
+                      WHERE stat_datetime >= date_format(
+                      date_sub(({date_time}, INTERVAL {day_count}-1 DAY),'%Y%m%d') 
+                    GROUP BY
+                    advertiser_id,
+                    campaign_id,
+                    campaign_name) report
 LEFT JOIN (
  SELECT
   cua.account_id id,

+ 165 - 342
Apietl/bytedance_etl/Q4Task/AppBytedanceCampaignReportBusiMonth.py

@@ -195,348 +195,171 @@ report.account_id,
  report.commute_first_pay_count
 FROM
  (
-  SELECT
-   advertiser_id account_id,
-   campaign_id campaign_id,
-   campaign_name campaign_name,
-   sum(cost) cost,
-   sum(`show`) `show`,
-   round(sum(cost) / sum(`show`), 3) avg_show_cost,
-   sum(click) click,
-   round(sum(cost) / sum(`click`), 3) avg_click_cost,
-   round(
-    sum(click) / sum(`show`) * 100,
-    3
-   ) ctr,
-   sum(`convert`) `convert`,
-   round(sum(cost) / sum(`convert`), 3) convert_cost,
-   round(
-    sum(`convert`) / sum(click) * 100,
-    3
-   ) convert_rate,
-   sum(deep_convert) deep_convert,
-   round(
-    sum(cost) / sum(deep_convert),
-    3
-   ) deep_convert_cost,
-   round(
-    sum(deep_convert) / sum(`convert`) * 100,
-    3
-   ) deep_convert_rate,
-   sum(attribution_convert) attribution_convert,
-   round(
-    sum(cost) / sum(attribution_convert),
-    3
-   ) attribution_convert_cost,
-   sum(attribution_deep_convert) attribution_deep_convert,
-   round(
-    sum(cost) / sum(attribution_deep_convert),
-    3
-   ) attribution_deep_convert_cost,
-   sum(download_start) download_start,
-   round(
-    sum(cost) / sum(download_start),
-    3
-   ) download_start_cost,
-   round(
-    sum(download_start) / sum(click),
-    3
-   ) download_start_rate,
-   sum(download_finish) download_finish,
-   round(
-    sum(cost) / sum(download_finish),
-    3
-   ) download_finish_cost,
-   round(
-    sum(download_finish) / sum(download_start) * 100,
-    3
-   ) download_finish_rate,
-   sum(click_install) click_install,
-   sum(install_finish) install_finish,
-   round(
-    sum(cost) / sum(install_finish),
-    3
-   ) install_finish_cost,
-   round(
-    sum(install_finish) / sum(download_finish) * 100,
-    3
-   ) install_finish_rate,
-   sum(active) active,
-   round(sum(cost) / sum(active), 3) active_cost,
-   round(
-    sum(active) / sum(click) * 100,
-    3
-   ) active_rate,
-   sum(register) register,
-   round(sum(cost) / sum(register), 3) active_register_cost,
-   round(
-    sum(active_register_rate) / {day_count} * 100,
-    3
-   ) active_register_rate,
-   sum(next_day_open) next_day_open,
-   round(
-    sum(cost) / sum(next_day_open),
-    3
-   ) next_day_open_cost,
-   round(
-    sum(next_day_open) / sum(active) * 100,
-    3
-   ) next_day_open_rate,
-   sum(
-    attribution_next_day_open_cnt
-   ) attribution_next_day_open_cnt,
-   round(
-    sum(cost) / sum(
-     attribution_next_day_open_cnt
-    ),
-    3
-   ) attribution_next_day_open_cost,
-   round(
-    sum(
-     attribution_next_day_open_cnt
-    ) / sum(active) * 100,
-    3
-   ) attribution_next_day_open_rate,
-   sum(game_addiction) game_addiction,
-   round(
-    sum(cost) / sum(game_addiction),
-    3
-   ) game_addiction_cost,
-   round(
-    sum(game_addiction_rate) / {day_count} * 100,
-    3
-   ) game_addiction_rate,
-   sum(pay_count) pay_count,
-   round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-   round(
-    sum(pay_count) / sum(active) * 100,
-    3
-   ) active_pay_rate,
-   sum(loan_completion) loan_completion,
-   round(
-    sum(cost) / sum(loan_completion),
-    3
-   ) loan_completion_cost,
-   round(
-    sum(loan_completion) / sum(register) * 100,
-    3
-   ) loan_completion_rate,
-   round(sum(pre_loan_credit), 3) pre_loan_credit,
-   round(
-    sum(cost) / sum(pre_loan_credit),
-    3
-   ) pre_loan_credit_cost,
-   sum(loan_credit) loan_credit,
-   round(
-    sum(cost) / sum(loan_credit),
-    3
-   ) loan_credit_cost,
-   round(
-    sum(loan_credit) / sum(loan_completion) * 100,
-    3
-   ) loan_credit_rate,
-   sum(in_app_uv) in_app_uv,
-   sum(in_app_detail_uv) in_app_detail_uv,
-   sum(in_app_cart) in_app_cart,
-   sum(in_app_pay) in_app_pay,
-   sum(in_app_order) in_app_order,
-   round(
-    sum(
-     attribution_game_pay_7d_count
-    ) / {day_count},
-    3
-   ) attribution_game_pay_7d_count,
-   round(
-    sum(
-     attribution_game_pay_7d_cost
-    ) / {day_count},
-    3
-   ) attribution_game_pay_7d_cost,
-   round(
-    sum(
-     attribution_active_pay_7d_per_count
-    ) / {day_count},
-    3
-   ) attribution_active_pay_7d_per_count,
-   sum(game_pay_cost) game_pay_cost,
-   sum(game_pay_count) game_pay_count,
-   sum(phone) phone,
-   sum(form) form,
-   sum(map_search) map_search,
-   sum(button) button,
-   sum(`view`) `view`,
-   sum(download) download,
-   sum(qq) qq,
-   sum(lottery) lottery,
-   sum(vote) vote,
-   sum(message) message,
-   sum(redirect) redirect,
-   sum(shopping) shopping,
-   sum(consult) consult,
-   sum(wechat) wechat,
-   sum(phone_confirm) phone_confirm,
-   sum(phone_connect) phone_connect,
-   sum(consult_effective) consult_effective,
-   sum(coupon) coupon,
-   sum(coupon_single_page) coupon_single_page,
-   sum(redirect_to_shop) redirect_to_shop,
-   sum(poi_collect) poi_collect,
-   sum(poi_address_click) poi_address_click,
-   sum(luban_order_cnt) luban_order_cnt,
-   sum(luban_order_stat_amount) luban_order_stat_amount,
-   sum(luban_order_roi) luban_order_roi,
-   sum(luban_live_enter_cnt) luban_live_enter_cnt,
-   sum(
-    live_watch_one_minute_count
-   ) live_watch_one_minute_count,
-   sum(luban_live_follow_cnt) luban_live_follow_cnt,
-   sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
-   sum(luban_live_comment_cnt) luban_live_comment_cnt,
-   sum(luban_live_share_cnt) luban_live_share_cnt,
-   sum(luban_live_gift_cnt) luban_live_gift_cnt,
-   sum(luban_live_gift_amount) luban_live_gift_amount,
-   sum(
-    luban_live_slidecart_click_cnt
-   ) luban_live_slidecart_click_cnt,
-   sum(
-    luban_live_click_product_cnt
-   ) luban_live_click_product_cnt,
-   sum(luban_live_pay_order_count) luban_live_pay_order_count,
-   sum(
-    luban_live_pay_order_stat_cost
-   ) luban_live_pay_order_stat_cost,
-   sum(live_component_click_count) live_component_click_count,
-   round(
-    sum(cost) / sum(live_component_click_count),
-    3
-   ) live_component_click_cost,
-   round(
-    sum(live_component_click_count) / {day_count} * 100,
-    3
-   ) live_component_click_rate,
-   sum(wechat_login_count) wechat_login_count,
-   sum(
-    attribution_wechat_login_30d_count
-   ) attribution_wechat_login_30d_count,
-   round(
-    sum(cost) / sum(wechat_login_count),
-    3
-   ) wechat_login_cost,
-   round(
-    sum(cost) / sum(
-     attribution_wechat_login_30d_count
-    ),
-    3
-   ) attribution_wechat_login_30d_cost,
-   sum(wechat_first_pay_count) wechat_first_pay_count,
-   sum(
-    attribution_wechat_first_pay_30d_count
-   ) attribution_wechat_first_pay_30d_count,
-   round(
-    sum(cost) / sum(wechat_first_pay_count),
-    3
-   ) wechat_first_pay_cost,
-   round(
-    sum(cost) / sum(
-     attribution_wechat_first_pay_30d_count
-    ),
-    3
-   ) attribution_wechat_first_pay_30d_cost,
-   round(
-    sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-    3
-   ) wechat_first_pay_rate,
-   round(
-    sum(
-     attribution_wechat_first_pay_30d_count
-    ) / sum(
-     attribution_wechat_login_30d_count
-    ) * 100,
-    3
-   ) attribution_wechat_first_pay_30d_rate,
-   sum(wechat_pay_amount) wechat_pay_amount,
-   sum(
-    attribution_wechat_pay_30d_amount
-   ) attribution_wechat_pay_30d_amount,
-   sum(
-    attribution_wechat_pay_30d_roi
-   ) attribution_wechat_pay_30d_roi,
-   sum(phone_effective) phone_effective,
-   sum(total_play) total_play,
-   sum(valid_play) valid_play,
-   round(
-    sum(cost) / sum(valid_play),
-    3
-   ) valid_play_cost,
-   round(
-    sum(valid_play) / sum(`show`) * 100,
-    3
-   ) valid_play_rate,
-   sum(play_25_feed_break) play_25_feed_break,
-   sum(play_50_feed_break) play_50_feed_break,
-   sum(play_75_feed_break) play_75_feed_break,
-   sum(play_100_feed_break) play_100_feed_break,
-   round(
-    sum(average_play_time_per_play) / {day_count},
-    3
-   ) average_play_time_per_play,
-   round(
-    sum(play_over_rate) / {day_count} * 100,
-    3
-   ) play_over_rate,
-   round(
-    sum(wifi_play) / sum(total_play) * 100,
-    3
-   ) wifi_play_rate,
-   sum(wifi_play) wifi_play,
-   round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-   sum(
-    advanced_creative_phone_click
-   ) advanced_creative_phone_click,
-   sum(
-    advanced_creative_counsel_click
-   ) advanced_creative_counsel_click,
-   sum(
-    advanced_creative_form_click
-   ) advanced_creative_form_click,
-   sum(
-    advanced_creative_coupon_addition
-   ) advanced_creative_coupon_addition,
-   sum(
-    advanced_creative_form_submit
-   ) advanced_creative_form_submit,
-   sum(card_show) card_show,
-   sum(`share`) `share`,
-   sum(`comment`) `comment`,
-   sum(`like`) `like`,
-   sum(follow) follow,
-   sum(home_visited) home_visited,
-   sum(ies_challenge_click) ies_challenge_click,
-   sum(ies_music_click) ies_music_click,
-   sum(location_click) location_click,
-   sum(message_action) message_action,
-   sum(click_landing_page) click_landing_page,
-   sum(click_shopwindow) click_shopwindow,
-   sum(click_website) click_website,
-   sum(click_download) click_download,
-   sum(click_call_dy) click_call_dy,
-   sum(submit_certification_count) submit_certification_count,
-   sum(approval_count) approval_count,
-   sum(first_order_count) first_rental_order_count,
-   sum(first_rental_order_count) first_order_count,
-   sum(commute_first_pay_count) commute_first_pay_count
-  FROM
-   `media_api`.bytedance_campaign_report_daily
-  WHERE
-   stat_datetime >= date_format(
-    date_sub({date_time}, INTERVAL {day_count}  DAY),
-    '%Y%m%d'
-   )
-  GROUP BY
-   advertiser_id,
-   campaign_id,
-   campaign_name
- ) report
+               SELECT
+                        advertiser_id account_id,
+                        campaign_id campaign_id,
+                        campaign_name campaign_name,
+                        sum(cost) cost,
+                        sum(`show`) `show`,
+                        ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+                        sum(click)click,
+                        ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+                        ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+                        sum(`convert`)`convert`,
+                        ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+                        ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+                        sum(deep_convert) deep_convert,
+                        ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+                        ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+                        sum(attribution_convert)attribution_convert,
+                        ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+                        sum(attribution_deep_convert) attribution_deep_convert,
+                        ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+                        sum(download_start) download_start,
+                        ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+                        ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+                        sum(download_finish) download_finish,
+                        ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+                        ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+                        sum(click_install)click_install,
+                        sum(install_finish) install_finish,
+                        ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+                        ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+                        sum(active) active,
+                        ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+                        ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+                        sum(register)register,
+                        ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+                        ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+                        sum(next_day_open)next_day_open,
+                        ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+                        ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+                        sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+                        ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+                        ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+                        sum(game_addiction) game_addiction,
+                        ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+                        ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+                        sum(pay_count)pay_count,
+                        ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+                        ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+                        sum(loan_completion) loan_completion,
+                        ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+                        ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+                        ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+                        ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+                        sum(loan_credit)loan_credit,
+                        ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+                        ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+                        sum(in_app_uv)in_app_uv,
+                        sum(in_app_detail_uv) in_app_detail_uv,
+                        sum(in_app_cart)in_app_cart,
+                        sum(in_app_pay) in_app_pay,
+                        sum(in_app_order) in_app_order,
+                        ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+                        ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+                        ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+                        sum(game_pay_cost)game_pay_cost,
+                        sum(game_pay_count) game_pay_count,
+                        sum(phone)phone,
+                        sum(form) form,
+                        sum(map_search) map_search,
+                        sum(button) button,
+                        sum(`view`) `view`,
+                        sum(download)download,
+                        sum(qq)qq,
+                        sum(lottery)lottery,
+                        sum(vote) vote,
+                        sum(message)message,
+                        sum(redirect)redirect,
+                        sum(shopping)shopping,
+                        sum(consult)consult,
+                        sum(wechat) wechat,
+                        sum(phone_confirm)phone_confirm,
+                        sum(phone_connect)phone_connect,
+                        sum(consult_effective)consult_effective,
+                        sum(coupon) coupon,
+                        sum(coupon_single_page) coupon_single_page,
+                        sum(redirect_to_shop) redirect_to_shop,
+                        sum(poi_collect)poi_collect,
+                        sum(poi_address_click)poi_address_click,
+                        sum(luban_order_cnt) luban_order_cnt,
+                        sum(luban_order_stat_amount)luban_order_stat_amount,
+                        sum(luban_order_roi) luban_order_roi,
+                        sum(luban_live_enter_cnt) luban_live_enter_cnt,
+                        sum(live_watch_one_minute_count) live_watch_one_minute_count,
+                        sum(luban_live_follow_cnt) luban_live_follow_cnt,
+                        sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+                        sum(luban_live_comment_cnt) luban_live_comment_cnt,
+                        sum(luban_live_share_cnt) luban_live_share_cnt,
+                        sum(luban_live_gift_cnt)luban_live_gift_cnt,
+                        sum(luban_live_gift_amount) luban_live_gift_amount,
+                        sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+                        sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+                        sum(luban_live_pay_order_count) luban_live_pay_order_count,
+                        sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+                        sum(live_component_click_count) live_component_click_count,
+                        ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+                        ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+                        sum(wechat_login_count) wechat_login_count,
+                        sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+                        ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+                        ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+                        sum(wechat_first_pay_count) wechat_first_pay_count,
+                        sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+                        ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+                        ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+                        ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+                        ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+                        sum(wechat_pay_amount)wechat_pay_amount,
+                        sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+                        sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+                        sum(phone_effective) phone_effective,
+                        sum(total_play) total_play,
+                        sum(valid_play) valid_play,
+                        ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+                        ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+                        sum(play_25_feed_break) play_25_feed_break,
+                        sum(play_50_feed_break) play_50_feed_break,
+                        sum(play_75_feed_break) play_75_feed_break,
+                        sum(play_100_feed_break)play_100_feed_break,
+                        ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+                        ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+                        ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+                        sum(wifi_play)wifi_play,
+                        ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+                        sum(advanced_creative_phone_click) advanced_creative_phone_click,
+                        sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+                        sum(advanced_creative_form_click) advanced_creative_form_click,
+                        sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+                        sum(advanced_creative_form_submit) advanced_creative_form_submit,
+                        sum(card_show)card_show,
+                        sum(`share`)`share`,
+                        sum(`comment`)`comment`,
+                        sum(`like`) `like`,
+                        sum(follow) follow,
+                        sum(home_visited) home_visited,
+                        sum(ies_challenge_click)ies_challenge_click,
+                        sum(ies_music_click) ies_music_click,
+                        sum(location_click) location_click,
+                        sum(message_action) message_action,
+                        sum(click_landing_page) click_landing_page,
+                        sum(click_shopwindow) click_shopwindow,
+                        sum(click_website)click_website,
+                        sum(click_download) click_download,
+                        sum(click_call_dy)click_call_dy,
+                        sum(submit_certification_count) submit_certification_count,
+                        sum(approval_count) approval_count,
+                        sum(first_order_count)first_rental_order_count,
+                        sum(first_rental_order_count) first_order_count,
+                        sum(commute_first_pay_count)commute_first_pay_count
+                      FROM `media_api`.bytedance_campaign_report_daily
+                      WHERE stat_datetime >= date_format(
+                      date_sub(({date_time}, INTERVAL {day_count} DAY),'%Y%m%d') 
+                    GROUP BY
+                    advertiser_id,
+                    campaign_id,
+                    campaign_name) report
 LEFT JOIN (
  SELECT
   cua.account_id id,

+ 190 - 401
Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyDesignReportBusi.py

@@ -24,392 +24,190 @@ class AppBytedanceCompanyDesignReportBusi:
             sql = """
 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_company_design_report_busi_{day_count}d
-SELECT concat(
-               date_format(
-                       date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
-                       '%Y%m%d'
-                   ),
-               '-',
-               {date_time}
-           )                                start_end_time,
-       company_id,
-       company_name,
-       org_code,
-       org_type,
-       id,
-       depart_name,
-       leader_id,
-       leader_name,
-       count(DISTINCT signature)            num,
-       count(distinct innovate_code)        innovate_num,
-       sum(cost)                            cost,
-       sum(`show`)                          `show`,
-       round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-       sum(click)                           click,
-       round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-       round(
-               sum(click) / sum(`show`) * 100,
-               3
-           )                                ctr,
-       sum(`convert`)                       `convert`,
-       round(sum(cost) / sum(`convert`), 3) convert_cost,
-       round(
-               sum(`convert`) / sum(click) * 100,
-               3
-           )                                convert_rate,
-       sum(deep_convert)                    deep_convert,
-       round(
-               sum(cost) / sum(deep_convert),
-               3
-           )                                deep_convert_cost,
-       round(
-               sum(deep_convert) / sum(`convert`) * 100,
-               3
-           )                                deep_convert_rate,
-       sum(attribution_convert)             attribution_convert,
-       round(
-               sum(cost) / sum(attribution_convert),
-               3
-           )                                attribution_convert_cost,
-       sum(attribution_deep_convert)        attribution_deep_convert,
-       round(
-               sum(cost) / sum(attribution_deep_convert),
-               3
-           )                                attribution_deep_convert_cost,
-       sum(download_start)                  download_start,
-       round(
-               sum(cost) / sum(download_start),
-               3
-           )                                download_start_cost,
-       round(
-               sum(download_start) / sum(click),
-               3
-           )                                download_start_rate,
-       sum(download_finish)                 download_finish,
-       round(
-               sum(cost) / sum(download_finish),
-               3
-           )                                download_finish_cost,
-       round(
-               sum(download_finish) / sum(download_start) * 100,
-               3
-           )                                download_finish_rate,
-       sum(click_install)                   click_install,
-       sum(install_finish)                  install_finish,
-       round(
-               sum(cost) / sum(install_finish),
-               3
-           )                                install_finish_cost,
-       round(
-               sum(install_finish) / sum(download_finish) * 100,
-               3
-           )                                install_finish_rate,
-       sum(active)                          active,
-       round(sum(cost) / sum(active), 3)    active_cost,
-       round(
-               sum(active) / sum(click) * 100,
-               3
-           )                                active_rate,
-       sum(register)                        register,
-       round(sum(cost) / sum(register), 3)  active_register_cost,
-       round(
-               sum(active_register_rate) / {day_count} * 100,
-               3
-           )                                active_register_rate,
-       sum(active_pay_amount)               active_pay_amount,
-       sum(next_day_open)                   next_day_open,
-       round(
-               sum(cost) / sum(next_day_open),
-               3
-           )                                next_day_open_cost,
-       round(
-               sum(next_day_open) / sum(active) * 100,
-               3
-           )                                next_day_open_rate,
-       sum(
-               attribution_next_day_open_cnt
-           )                                attribution_next_day_open_cnt,
-       round(
-                   sum(cost) / sum(
-                       attribution_next_day_open_cnt
-                   ),
-                   3
-           )                                attribution_next_day_open_cost,
-       round(
-                       sum(
-                               attribution_next_day_open_cnt
-                           ) / sum(active) * 100,
-                       3
-           )                                attribution_next_day_open_rate,
-       sum(game_addiction)                  game_addiction,
-       round(
-               sum(cost) / sum(game_addiction),
-               3
-           )                                game_addiction_cost,
-       round(
-               sum(game_addiction_rate) / {day_count} * 100,
-               3
-           )                                game_addiction_rate,
-       sum(pay_count)                       pay_count,
-       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-       round(
-               sum(pay_count) / sum(active) * 100,
-               3
-           )                                active_pay_rate,
-       sum(loan_completion)                 loan_completion,
-       round(
-               sum(cost) / sum(loan_completion),
-               3
-           )                                loan_completion_cost,
-       round(
-               sum(loan_completion) / sum(register) * 100,
-               3
-           )                                loan_completion_rate,
-       round(sum(pre_loan_credit), 3)       pre_loan_credit,
-       round(
-               sum(cost) / sum(pre_loan_credit),
-               3
-           )                                pre_loan_credit_cost,
-       sum(loan_credit)                     loan_credit,
-       round(
-               sum(cost) / sum(loan_credit),
-               3
-           )                                loan_credit_cost,
-       round(
-               sum(loan_credit) / sum(loan_completion) * 100,
-               3
-           )                                loan_credit_rate,
-       sum(in_app_uv)                       in_app_uv,
-       sum(in_app_detail_uv)                in_app_detail_uv,
-       sum(in_app_cart)                     in_app_cart,
-       sum(in_app_pay)                      in_app_pay,
-       sum(in_app_order)                    in_app_order,
-       round(
-                   sum(
-                           attribution_game_pay_7d_count
-                       ) / {day_count},
-                   3
-           )                                attribution_game_pay_7d_count,
-       round(
-                   sum(
-                           attribution_game_pay_7d_cost
-                       ) / {day_count},
-                   3
-           )                                attribution_game_pay_7d_cost,
-       round(
-                   sum(
-                           attribution_active_pay_7d_per_count
-                       ) / {day_count},
-                   3
-           )                                attribution_active_pay_7d_per_count,
-       sum(game_pay_cost)                   game_pay_cost,
-       sum(game_pay_count)                  game_pay_count,
-       sum(phone)                           phone,
-       sum(form)                            form,
-       sum(map_search)                      map_search,
-       sum(button)                          button,
-       sum(`view`)                          `view`,
-       sum(download)                        download,
-       sum(qq)                              qq,
-       sum(lottery)                         lottery,
-       sum(vote)                            vote,
-       sum(message)                         message,
-       sum(redirect)                        redirect,
-       sum(shopping)                        shopping,
-       sum(consult)                         consult,
-       sum(wechat)                          wechat,
-       sum(phone_confirm)                   phone_confirm,
-       sum(phone_connect)                   phone_connect,
-       sum(consult_effective)               consult_effective,
-       sum(coupon)                          coupon,
-       sum(coupon_single_page)              coupon_single_page,
-       sum(redirect_to_shop)                redirect_to_shop,
-       sum(poi_collect)                     poi_collect,
-       sum(poi_address_click)               poi_address_click,
-       sum(luban_order_cnt)                 luban_order_cnt,
-       sum(luban_order_stat_amount)         luban_order_stat_amount,
-       sum(luban_order_roi)                 luban_order_roi,
-       sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-       sum(
-               live_watch_one_minute_count
-           )                                live_watch_one_minute_count,
-       sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-       sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-       sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-       sum(luban_live_share_cnt)            luban_live_share_cnt,
-       sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-       sum(luban_live_gift_amount)          luban_live_gift_amount,
-       sum(
-               luban_live_slidecart_click_cnt
-           )                                luban_live_slidecart_click_cnt,
-       sum(
-               luban_live_click_product_cnt
-           )                                luban_live_click_product_cnt,
-       sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-       sum(
-               luban_live_pay_order_stat_cost
-           )                                luban_live_pay_order_stat_cost,
-       sum(wechat_login_count)              wechat_login_count,
-       sum(
-               attribution_wechat_login_30d_count
-           )                                attribution_wechat_login_30d_count,
-       round(
-               sum(cost) / sum(wechat_login_count),
-               3
-           )                                wechat_login_cost,
-       round(
-                   sum(cost) / sum(
-                       attribution_wechat_login_30d_count
-                   ),
-                   3
-           )                                attribution_wechat_login_30d_cost,
-       sum(wechat_first_pay_count)          wechat_first_pay_count,
-       sum(
-               attribution_wechat_first_pay_30d_count
-           )                                attribution_wechat_first_pay_30d_count,
-       round(
-               sum(cost) / sum(wechat_first_pay_count),
-               3
-           )                                wechat_first_pay_cost,
-       round(
-                   sum(cost) / sum(
-                       attribution_wechat_first_pay_30d_count
-                   ),
-                   3
-           )                                attribution_wechat_first_pay_30d_cost,
-       round(
-               sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-               3
-           )                                wechat_first_pay_rate,
-       round(
-                       sum(
-                               attribution_wechat_first_pay_30d_count
-                           ) / sum(
-                               attribution_wechat_login_30d_count
-                           ) * 100,
-                       3
-           )                                attribution_wechat_first_pay_30d_rate,
-       sum(wechat_pay_amount)               wechat_pay_amount,
-       sum(
-               attribution_wechat_pay_30d_amount
-           )                                attribution_wechat_pay_30d_amount,
-       sum(
-               attribution_wechat_pay_30d_roi
-           )                                attribution_wechat_pay_30d_roi,
-       sum(phone_effective)                 phone_effective,
-       sum(total_play)                      total_play,
-       sum(valid_play)                      valid_play,
-       round(
-               sum(cost) / sum(valid_play),
-               3
-           )                                valid_play_cost,
-       round(
-               sum(valid_play) / sum(`show`) * 100,
-               3
-           )                                valid_play_rate,
-       sum(play_25_feed_break)              play_25_feed_break,
-       sum(play_50_feed_break)              play_50_feed_break,
-       sum(play_75_feed_break)              play_75_feed_break,
-       sum(play_100_feed_break)             play_100_feed_break,
-       round(
-               sum(average_play_time_per_play) / {day_count},
-               3
-           )                                average_play_time_per_play,
-       round(
-               sum(play_over_rate) / {day_count} * 100,
-               3
-           )                                play_over_rate,
-       round(
-               sum(wifi_play) / sum(total_play) * 100,
-               3
-           )                                wifi_play_rate,
-       sum(wifi_play)                       wifi_play,
-       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-       sum(
-               advanced_creative_phone_click
-           )                                advanced_creative_phone_click,
-       sum(
-               advanced_creative_counsel_click
-           )                                advanced_creative_counsel_click,
-       sum(
-               advanced_creative_form_click
-           )                                advanced_creative_form_click,
-       sum(
-               advanced_creative_coupon_addition
-           )                                advanced_creative_coupon_addition,
-       sum(
-               advanced_creative_form_submit
-           )                                advanced_creative_form_submit,
-       sum(card_show)                       card_show,
-       sum(`share`)                         `share`,
-       sum(`comment`)                       `comment`,
-       sum(`like`)                          `like`,
-       sum(follow)                          follow,
-       sum(home_visited)                    home_visited,
-       sum(ies_challenge_click)             ies_challenge_click,
-       sum(ies_music_click)                 ies_music_click,
-       sum(location_click)                  location_click,
-       sum(message_action)                  message_action,
-       sum(click_landing_page)              click_landing_page,
-       sum(click_shopwindow)                click_shopwindow,
-       sum(click_website)                   click_website,
-       sum(click_download)                  click_download,
-       sum(click_call_dy)                   click_call_dy,
-       sum(cpc)                             cpc,
-       sum(cpm)                             cpm,
-       sum(cpa)                             cpa,
-       round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
-       round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
-       round(
-               sum(round(play_duration_10s)) / sum(total_play) * 100,
-               3
-           )                                play_duration_10s_rate,
-       round(
-               sum(play_50_feed_break) / sum(total_play) * 100,
-               3
-           )                                play_50_feed_break_rate,
-       round(
-               sum(play_25_feed_break) / sum(total_play) * 100,
-               3
-           )                                play_25_feed_break_rate,
-       round(
-               sum(play_duration_5s_rate) / {day_count},
-               3
-           )                                play_duration_5s_rate,
-       round(
-               sum(play_duration_2s) / sum(total_play) * 100,
-               3
-           )                                play_duration_2s_rate,
-       round(
-               sum(average_play_progress) / {day_count},
-               3
-           )                                average_play_progress,
-       round(
-               sum(play_100_feed_break) / sum(total_play) * 100,
-               3
-           )                                play_100_feed_break_rate,
-       round(
-               sum(play_duration_3s) / sum(total_play) * 100,
-               3
-           )                                play_duration_3s_rate,
-       round(
-               sum(play_75_feed_break) / sum(total_play) * 100,
-               3
-           )                                play_75_feed_break_rate,
-       sum(play_duration)                   play_duration,
-       sum(play_duration_3s)                play_duration_3s,
-       sum(play_duration_2s)                play_duration_2s,
-       sum(play_duration_10s)               play_duration_10s,
-       round(
-               sum(average_video_play) / {day_count},
-               3
-           )                                average_video_play,
-       sum(avg_rank)                        avg_rank,
-       sum(submit_certification_count)      submit_certification_count,
-       sum(approval_count)                  approval_count,
-       sum(first_order_count)               first_rental_order_count,
-       sum(first_rental_order_count)        first_order_count,
-       sum(commute_first_pay_count)         commute_first_pay_count
+SELECT    concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d'),'-',{date_time})  as
+          start_end_time,
+          ifnull(company_id,'-') company_id,
+          company_name,
+          org_code,
+          org_type,
+          id,
+          depart_name,
+          ifnull(leader_id,'-') leader_id,
+          leader_name,
+          count(DISTINCT signature) num,
+          count(DISTINCT innovate_code) innovate_num,
+          sum(cost) cost,
+          sum(`show`) `show`,
+          ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+          sum(click) click,
+          ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+          ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+          sum(`convert`) `convert`,
+          ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+          ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+          sum(deep_convert) deep_convert,
+          ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
+          ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+          sum(attribution_convert) attribution_convert,
+          ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
+          sum(attribution_deep_convert) attribution_deep_convert,
+          ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
+          sum(download_start) download_start,
+          ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
+          ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
+          sum(download_finish) download_finish,
+          ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
+          ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+          sum(click_install) click_install,
+          sum(install_finish) install_finish,
+          ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
+          ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+          sum(active) active,
+          ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+          ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+          sum(register) register,
+          ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+          ifnull(round(sum(active_register_rate) /{day_count} * 100,3),0) active_register_rate,
+          sum(active_pay_amount) active_pay_amount,
+          sum(next_day_open) next_day_open,
+          ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
+          ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+          sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+          ifnull(round(sum(cost) / sum(	attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
+          ifnull(round(sum(	attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+          sum(game_addiction) game_addiction,
+          ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
+          ifnull(round(sum(game_addiction_rate) /{day_count} * 100,3),0) game_addiction_rate,
+          sum(pay_count) pay_count,
+          ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+          ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+          sum(loan_completion) loan_completion,
+          ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
+          ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+          ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+          ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
+          sum(loan_credit) loan_credit,
+          ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
+          ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+          sum(in_app_uv) in_app_uv,
+          sum(in_app_detail_uv) in_app_detail_uv,
+          sum(in_app_cart) in_app_cart,
+          sum(in_app_pay) in_app_pay,
+          sum(in_app_order) in_app_order,
+          ifnull(round(sum(	attribution_game_pay_7d_count) /{day_count}, 3),0) attribution_game_pay_7d_count,
+          ifnull(round(sum(	attribution_game_pay_7d_cost) /{day_count}, 3),0) attribution_game_pay_7d_cost,
+          ifnull(round(sum(	attribution_active_pay_7d_per_count) /{day_count}, 3),0) attribution_active_pay_7d_per_count,
+          sum(game_pay_cost) game_pay_cost,
+          sum(game_pay_count) game_pay_count,
+          sum(phone) phone,
+          sum(form) form,
+          sum(map_search) map_search,
+          sum(button) button,
+          sum(`view`) `view`,
+          sum(download) download,
+          sum(qq) qq,
+          sum(lottery) lottery,
+          sum(vote) vote,
+          sum(message) message,
+          sum(redirect) redirect,
+          sum(shopping) shopping,
+          sum(consult) consult,
+          sum(wechat) wechat,
+          sum(phone_confirm) phone_confirm,
+          sum(phone_connect) phone_connect,
+          sum(consult_effective) consult_effective,
+          sum(coupon) coupon,
+          sum(coupon_single_page) coupon_single_page,
+          sum(redirect_to_shop) redirect_to_shop,
+          sum(poi_collect) poi_collect,
+          sum(poi_address_click) poi_address_click,
+          sum(luban_order_cnt) luban_order_cnt,
+          sum(luban_order_stat_amount) luban_order_stat_amount,
+          sum(luban_order_roi) luban_order_roi,
+          sum(luban_live_enter_cnt) luban_live_enter_cnt,
+          sum(live_watch_one_minute_count) live_watch_one_minute_count,
+          sum(luban_live_follow_cnt) luban_live_follow_cnt,
+          sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+          sum(luban_live_comment_cnt) luban_live_comment_cnt,
+          sum(luban_live_share_cnt) luban_live_share_cnt,
+          sum(luban_live_gift_cnt) luban_live_gift_cnt,
+          sum(luban_live_gift_amount) luban_live_gift_amount,
+          sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+          sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+          sum(luban_live_pay_order_count) luban_live_pay_order_count,
+          sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+          sum(wechat_login_count) wechat_login_count,
+          sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
+          sum(wechat_first_pay_count) wechat_first_pay_count,
+          sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
+          ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+          ifnull(round(sum(	attribution_wechat_first_pay_30d_count) / sum(	attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+          sum(wechat_pay_amount) wechat_pay_amount,
+          sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+          sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+          sum(phone_effective) phone_effective,
+          sum(total_play) total_play,
+          sum(valid_play) valid_play,
+          ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
+          ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+          sum(play_25_feed_break) play_25_feed_break,
+          sum(play_50_feed_break) play_50_feed_break,
+          sum(play_75_feed_break) play_75_feed_break,
+          sum(play_100_feed_break) play_100_feed_break,
+          ifnull(round(sum(average_play_time_per_play) /{day_count}, 3),0) average_play_time_per_play,
+          ifnull(round(sum(play_over_rate) /{day_count} * 100,3),0) play_over_rate,
+          ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+          sum(wifi_play) wifi_play,
+          ifnull(round(sum(play_duration_sum) /{day_count}, 3),0) play_duration_sum,
+          sum(advanced_creative_phone_click) advanced_creative_phone_click,
+          sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+          sum(advanced_creative_form_click) advanced_creative_form_click,
+          sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+          sum(advanced_creative_form_submit) advanced_creative_form_submit,
+          sum(card_show) card_show,
+          sum(`share`) `share`,
+          sum(`comment`) `comment`,
+          sum(`like`) `like`,
+          sum(follow) follow,
+          sum(home_visited) home_visited,
+          sum(ies_challenge_click) ies_challenge_click,
+          sum(ies_music_click) ies_music_click,
+          sum(location_click) location_click,
+          sum(message_action) message_action,
+          sum(click_landing_page) click_landing_page,
+          sum(click_shopwindow) click_shopwindow,
+          sum(click_website) click_website,
+          sum(click_download) click_download,
+          sum(click_call_dy) click_call_dy,
+          sum(cpc) cpc,
+          sum(cpm) cpm,
+          sum(cpa) cpa,
+          ifnull(round(sum(interact_per_cost) /{day_count}, 3),0) interact_per_cost,
+          ifnull(round(sum(convert_show_rate) /{day_count}, 3),0) convert_show_rate,
+          ifnull(round(sum(play_duration_10s) / sum(total_play) * 100,3),0) play_duration_10s_rate,
+          ifnull(round(sum(play_50_feed_break) / sum(total_play) * 100,3),0) play_50_feed_break_rate,
+          ifnull(round(sum(play_25_feed_break) / sum(total_play) * 100,3),0) play_25_feed_break_rate,
+          ifnull(round(sum(play_duration_5s_rate) /{day_count}, 3),0) play_duration_5s_rate,
+          ifnull(round(sum(play_duration_2s) / sum(total_play) * 100,3),0) play_duration_2s_rate,
+          ifnull(round(sum(average_play_progress) /{day_count}, 3),0) average_play_progress,
+          ifnull(round(sum(play_100_feed_break) / sum(total_play) * 100,3),0) play_100_feed_break_rate,
+          ifnull(round(sum(play_duration_3s) / sum(total_play) * 100,3),0) play_duration_3s_rate,
+          ifnull(round(sum(play_75_feed_break) / sum(total_play) * 100,3),0) play_75_feed_break_rate,
+          sum(play_duration) play_duration,
+          sum(play_duration_3s) play_duration_3s,
+          sum(play_duration_2s) play_duration_2s,
+          sum(play_duration_10s) play_duration_10s,
+          ifnull(round(sum(average_video_play) /{day_count}, 3),0) average_video_play,
+          sum(avg_rank) avg_rank,
+          sum(submit_certification_count) submit_certification_count,
+          sum(approval_count) approval_count,
+          sum(first_order_count) first_rental_order_count,
+          sum(first_rental_order_count) first_order_count,
+          sum(commute_first_pay_count) commute_first_pay_count
 FROM (
          SELECT video.signature,
                 uc.company_id,
@@ -422,7 +220,7 @@ FROM (
                         '上海汇创思拓数字科技有限公司'
                     ELSE
                         uc.company_name
-                    END                                                              company_name,
+                    END  company_name,
                 cma.leader_id,
                 us.realname as leader_name,
                 ur.org_type,
@@ -644,20 +442,11 @@ FROM (
          WHERE image_mode IN (
                               'CREATIVE_IMAGE_MODE_VIDEO',
                               'CREATIVE_IMAGE_MODE_VIDEO_VERTICAL',
-                              'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO'
-             )
-           AND stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
-                 '%Y%m%d'
-             )
-     ) info
-GROUP BY company_id,
-         company_name,
-         leader_id,
-         org_type,
-         org_code,
-         id,
-         depart_name;
+                              'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO')
+          AND stat_datetime >= date_format( date_sub({date_time}, INTERVAL {day_count}-1 DAY),'%Y%m%d')) info
+          GROUP BY 
+          company_id,
+          leader_id;
             """.format(date_time=self.date_time, day_count=self.day_count)
             TidbConn.upsert(conn=self.conn, sql_buff=sql)
             self.conn.commit()

+ 192 - 393
Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyDesignReportBusiMonth.py

@@ -27,384 +27,188 @@ SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_
 REPLACE INTO application.app_bytedance_company_design_report_busi_m
 SELECT 
        date_format({date_time},'%Y%m')    as  stat_mon,
-       company_id,
-       company_name,
-       org_code,
-       org_type,
-       id,
-       depart_name,
-       leader_id,
-       leader_name,
-       count(DISTINCT signature)            num,
-       count(distinct innovate_code)        innovate_num,
-       sum(cost)                            cost,
-       sum(`show`)                          `show`,
-       round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-       sum(click)                           click,
-       round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-       round(
-               sum(click) / sum(`show`) * 100,
-               3
-           )                                ctr,
-       sum(`convert`)                       `convert`,
-       round(sum(cost) / sum(`convert`), 3) convert_cost,
-       round(
-               sum(`convert`) / sum(click) * 100,
-               3
-           )                                convert_rate,
-       sum(deep_convert)                    deep_convert,
-       round(
-               sum(cost) / sum(deep_convert),
-               3
-           )                                deep_convert_cost,
-       round(
-               sum(deep_convert) / sum(`convert`) * 100,
-               3
-           )                                deep_convert_rate,
-       sum(attribution_convert)             attribution_convert,
-       round(
-               sum(cost) / sum(attribution_convert),
-               3
-           )                                attribution_convert_cost,
-       sum(attribution_deep_convert)        attribution_deep_convert,
-       round(
-               sum(cost) / sum(attribution_deep_convert),
-               3
-           )                                attribution_deep_convert_cost,
-       sum(download_start)                  download_start,
-       round(
-               sum(cost) / sum(download_start),
-               3
-           )                                download_start_cost,
-       round(
-               sum(download_start) / sum(click),
-               3
-           )                                download_start_rate,
-       sum(download_finish)                 download_finish,
-       round(
-               sum(cost) / sum(download_finish),
-               3
-           )                                download_finish_cost,
-       round(
-               sum(download_finish) / sum(download_start) * 100,
-               3
-           )                                download_finish_rate,
-       sum(click_install)                   click_install,
-       sum(install_finish)                  install_finish,
-       round(
-               sum(cost) / sum(install_finish),
-               3
-           )                                install_finish_cost,
-       round(
-               sum(install_finish) / sum(download_finish) * 100,
-               3
-           )                                install_finish_rate,
-       sum(active)                          active,
-       round(sum(cost) / sum(active), 3)    active_cost,
-       round(
-               sum(active) / sum(click) * 100,
-               3
-           )                                active_rate,
-       sum(register)                        register,
-       round(sum(cost) / sum(register), 3)  active_register_cost,
-       round(
-               sum(active_register_rate) / {day_count} * 100,
-               3
-           )                                active_register_rate,
-       sum(active_pay_amount)               active_pay_amount,
-       sum(next_day_open)                   next_day_open,
-       round(
-               sum(cost) / sum(next_day_open),
-               3
-           )                                next_day_open_cost,
-       round(
-               sum(next_day_open) / sum(active) * 100,
-               3
-           )                                next_day_open_rate,
-       sum(
-               attribution_next_day_open_cnt
-           )                                attribution_next_day_open_cnt,
-       round(
-                   sum(cost) / sum(
-                       attribution_next_day_open_cnt
-                   ),
-                   3
-           )                                attribution_next_day_open_cost,
-       round(
-                       sum(
-                               attribution_next_day_open_cnt
-                           ) / sum(active) * 100,
-                       3
-           )                                attribution_next_day_open_rate,
-       sum(game_addiction)                  game_addiction,
-       round(
-               sum(cost) / sum(game_addiction),
-               3
-           )                                game_addiction_cost,
-       round(
-               sum(game_addiction_rate) / {day_count} * 100,
-               3
-           )                                game_addiction_rate,
-       sum(pay_count)                       pay_count,
-       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-       round(
-               sum(pay_count) / sum(active) * 100,
-               3
-           )                                active_pay_rate,
-       sum(loan_completion)                 loan_completion,
-       round(
-               sum(cost) / sum(loan_completion),
-               3
-           )                                loan_completion_cost,
-       round(
-               sum(loan_completion) / sum(register) * 100,
-               3
-           )                                loan_completion_rate,
-       round(sum(pre_loan_credit), 3)       pre_loan_credit,
-       round(
-               sum(cost) / sum(pre_loan_credit),
-               3
-           )                                pre_loan_credit_cost,
-       sum(loan_credit)                     loan_credit,
-       round(
-               sum(cost) / sum(loan_credit),
-               3
-           )                                loan_credit_cost,
-       round(
-               sum(loan_credit) / sum(loan_completion) * 100,
-               3
-           )                                loan_credit_rate,
-       sum(in_app_uv)                       in_app_uv,
-       sum(in_app_detail_uv)                in_app_detail_uv,
-       sum(in_app_cart)                     in_app_cart,
-       sum(in_app_pay)                      in_app_pay,
-       sum(in_app_order)                    in_app_order,
-       round(
-                   sum(
-                           attribution_game_pay_7d_count
-                       ) / {day_count},
-                   3
-           )                                attribution_game_pay_7d_count,
-       round(
-                   sum(
-                           attribution_game_pay_7d_cost
-                       ) / {day_count},
-                   3
-           )                                attribution_game_pay_7d_cost,
-       round(
-                   sum(
-                           attribution_active_pay_7d_per_count
-                       ) / {day_count},
-                   3
-           )                                attribution_active_pay_7d_per_count,
-       sum(game_pay_cost)                   game_pay_cost,
-       sum(game_pay_count)                  game_pay_count,
-       sum(phone)                           phone,
-       sum(form)                            form,
-       sum(map_search)                      map_search,
-       sum(button)                          button,
-       sum(`view`)                          `view`,
-       sum(download)                        download,
-       sum(qq)                              qq,
-       sum(lottery)                         lottery,
-       sum(vote)                            vote,
-       sum(message)                         message,
-       sum(redirect)                        redirect,
-       sum(shopping)                        shopping,
-       sum(consult)                         consult,
-       sum(wechat)                          wechat,
-       sum(phone_confirm)                   phone_confirm,
-       sum(phone_connect)                   phone_connect,
-       sum(consult_effective)               consult_effective,
-       sum(coupon)                          coupon,
-       sum(coupon_single_page)              coupon_single_page,
-       sum(redirect_to_shop)                redirect_to_shop,
-       sum(poi_collect)                     poi_collect,
-       sum(poi_address_click)               poi_address_click,
-       sum(luban_order_cnt)                 luban_order_cnt,
-       sum(luban_order_stat_amount)         luban_order_stat_amount,
-       sum(luban_order_roi)                 luban_order_roi,
-       sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-       sum(
-               live_watch_one_minute_count
-           )                                live_watch_one_minute_count,
-       sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-       sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-       sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-       sum(luban_live_share_cnt)            luban_live_share_cnt,
-       sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-       sum(luban_live_gift_amount)          luban_live_gift_amount,
-       sum(
-               luban_live_slidecart_click_cnt
-           )                                luban_live_slidecart_click_cnt,
-       sum(
-               luban_live_click_product_cnt
-           )                                luban_live_click_product_cnt,
-       sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-       sum(
-               luban_live_pay_order_stat_cost
-           )                                luban_live_pay_order_stat_cost,
-       sum(wechat_login_count)              wechat_login_count,
-       sum(
-               attribution_wechat_login_30d_count
-           )                                attribution_wechat_login_30d_count,
-       round(
-               sum(cost) / sum(wechat_login_count),
-               3
-           )                                wechat_login_cost,
-       round(
-                   sum(cost) / sum(
-                       attribution_wechat_login_30d_count
-                   ),
-                   3
-           )                                attribution_wechat_login_30d_cost,
-       sum(wechat_first_pay_count)          wechat_first_pay_count,
-       sum(
-               attribution_wechat_first_pay_30d_count
-           )                                attribution_wechat_first_pay_30d_count,
-       round(
-               sum(cost) / sum(wechat_first_pay_count),
-               3
-           )                                wechat_first_pay_cost,
-       round(
-                   sum(cost) / sum(
-                       attribution_wechat_first_pay_30d_count
-                   ),
-                   3
-           )                                attribution_wechat_first_pay_30d_cost,
-       round(
-               sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-               3
-           )                                wechat_first_pay_rate,
-       round(
-                       sum(
-                               attribution_wechat_first_pay_30d_count
-                           ) / sum(
-                               attribution_wechat_login_30d_count
-                           ) * 100,
-                       3
-           )                                attribution_wechat_first_pay_30d_rate,
-       sum(wechat_pay_amount)               wechat_pay_amount,
-       sum(
-               attribution_wechat_pay_30d_amount
-           )                                attribution_wechat_pay_30d_amount,
-       sum(
-               attribution_wechat_pay_30d_roi
-           )                                attribution_wechat_pay_30d_roi,
-       sum(phone_effective)                 phone_effective,
-       sum(total_play)                      total_play,
-       sum(valid_play)                      valid_play,
-       round(
-               sum(cost) / sum(valid_play),
-               3
-           )                                valid_play_cost,
-       round(
-               sum(valid_play) / sum(`show`) * 100,
-               3
-           )                                valid_play_rate,
-       sum(play_25_feed_break)              play_25_feed_break,
-       sum(play_50_feed_break)              play_50_feed_break,
-       sum(play_75_feed_break)              play_75_feed_break,
-       sum(play_100_feed_break)             play_100_feed_break,
-       round(
-               sum(average_play_time_per_play) / {day_count},
-               3
-           )                                average_play_time_per_play,
-       round(
-               sum(play_over_rate) / {day_count} * 100,
-               3
-           )                                play_over_rate,
-       round(
-               sum(wifi_play) / sum(total_play) * 100,
-               3
-           )                                wifi_play_rate,
-       sum(wifi_play)                       wifi_play,
-       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-       sum(
-               advanced_creative_phone_click
-           )                                advanced_creative_phone_click,
-       sum(
-               advanced_creative_counsel_click
-           )                                advanced_creative_counsel_click,
-       sum(
-               advanced_creative_form_click
-           )                                advanced_creative_form_click,
-       sum(
-               advanced_creative_coupon_addition
-           )                                advanced_creative_coupon_addition,
-       sum(
-               advanced_creative_form_submit
-           )                                advanced_creative_form_submit,
-       sum(card_show)                       card_show,
-       sum(`share`)                         `share`,
-       sum(`comment`)                       `comment`,
-       sum(`like`)                          `like`,
-       sum(follow)                          follow,
-       sum(home_visited)                    home_visited,
-       sum(ies_challenge_click)             ies_challenge_click,
-       sum(ies_music_click)                 ies_music_click,
-       sum(location_click)                  location_click,
-       sum(message_action)                  message_action,
-       sum(click_landing_page)              click_landing_page,
-       sum(click_shopwindow)                click_shopwindow,
-       sum(click_website)                   click_website,
-       sum(click_download)                  click_download,
-       sum(click_call_dy)                   click_call_dy,
-       sum(cpc)                             cpc,
-       sum(cpm)                             cpm,
-       sum(cpa)                             cpa,
-       round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
-       round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
-       round(
-               sum(round(play_duration_10s)) / sum(total_play) * 100,
-               3
-           )                                play_duration_10s_rate,
-       round(
-               sum(play_50_feed_break) / sum(total_play) * 100,
-               3
-           )                                play_50_feed_break_rate,
-       round(
-               sum(play_25_feed_break) / sum(total_play) * 100,
-               3
-           )                                play_25_feed_break_rate,
-       round(
-               sum(play_duration_5s_rate) / {day_count},
-               3
-           )                                play_duration_5s_rate,
-       round(
-               sum(play_duration_2s) / sum(total_play) * 100,
-               3
-           )                                play_duration_2s_rate,
-       round(
-               sum(average_play_progress) / {day_count},
-               3
-           )                                average_play_progress,
-       round(
-               sum(play_100_feed_break) / sum(total_play) * 100,
-               3
-           )                                play_100_feed_break_rate,
-       round(
-               sum(play_duration_3s) / sum(total_play) * 100,
-               3
-           )                                play_duration_3s_rate,
-       round(
-               sum(play_75_feed_break) / sum(total_play) * 100,
-               3
-           )                                play_75_feed_break_rate,
-       sum(play_duration)                   play_duration,
-       sum(play_duration_3s)                play_duration_3s,
-       sum(play_duration_2s)                play_duration_2s,
-       sum(play_duration_10s)               play_duration_10s,
-       round(
-               sum(average_video_play) / {day_count},
-               3
-           )                                average_video_play,
-       sum(avg_rank)                        avg_rank,
-       sum(submit_certification_count)      submit_certification_count,
-       sum(approval_count)                  approval_count,
-       sum(first_order_count)               first_rental_order_count,
-       sum(first_rental_order_count)        first_order_count,
-       sum(commute_first_pay_count)         commute_first_pay_count
+          ifnull(company_id,'-') company_id,
+          company_name,
+          org_code,
+          org_type,
+          id,
+          depart_name,
+          ifnull(leader_id,'-') leader_id,
+          leader_name,
+          count(DISTINCT signature) num,
+          count(DISTINCT innovate_code) innovate_num,
+          sum(cost) cost,
+          sum(`show`) `show`,
+          ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+          sum(click) click,
+          ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+          ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+          sum(`convert`) `convert`,
+          ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+          ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+          sum(deep_convert) deep_convert,
+          ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
+          ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+          sum(attribution_convert) attribution_convert,
+          ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
+          sum(attribution_deep_convert) attribution_deep_convert,
+          ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
+          sum(download_start) download_start,
+          ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
+          ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
+          sum(download_finish) download_finish,
+          ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
+          ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+          sum(click_install) click_install,
+          sum(install_finish) install_finish,
+          ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
+          ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+          sum(active) active,
+          ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+          ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+          sum(register) register,
+          ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+          ifnull(round(sum(active_register_rate) /{day_count} * 100,3),0) active_register_rate,
+          sum(active_pay_amount) active_pay_amount,
+          sum(next_day_open) next_day_open,
+          ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
+          ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+          sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+          ifnull(round(sum(cost) / sum(	attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
+          ifnull(round(sum(	attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+          sum(game_addiction) game_addiction,
+          ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
+          ifnull(round(sum(game_addiction_rate) /{day_count} * 100,3),0) game_addiction_rate,
+          sum(pay_count) pay_count,
+          ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+          ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+          sum(loan_completion) loan_completion,
+          ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
+          ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+          ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+          ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
+          sum(loan_credit) loan_credit,
+          ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
+          ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+          sum(in_app_uv) in_app_uv,
+          sum(in_app_detail_uv) in_app_detail_uv,
+          sum(in_app_cart) in_app_cart,
+          sum(in_app_pay) in_app_pay,
+          sum(in_app_order) in_app_order,
+          ifnull(round(sum(	attribution_game_pay_7d_count) /{day_count}, 3),0) attribution_game_pay_7d_count,
+          ifnull(round(sum(	attribution_game_pay_7d_cost) /{day_count}, 3),0) attribution_game_pay_7d_cost,
+          ifnull(round(sum(	attribution_active_pay_7d_per_count) /{day_count}, 3),0) attribution_active_pay_7d_per_count,
+          sum(game_pay_cost) game_pay_cost,
+          sum(game_pay_count) game_pay_count,
+          sum(phone) phone,
+          sum(form) form,
+          sum(map_search) map_search,
+          sum(button) button,
+          sum(`view`) `view`,
+          sum(download) download,
+          sum(qq) qq,
+          sum(lottery) lottery,
+          sum(vote) vote,
+          sum(message) message,
+          sum(redirect) redirect,
+          sum(shopping) shopping,
+          sum(consult) consult,
+          sum(wechat) wechat,
+          sum(phone_confirm) phone_confirm,
+          sum(phone_connect) phone_connect,
+          sum(consult_effective) consult_effective,
+          sum(coupon) coupon,
+          sum(coupon_single_page) coupon_single_page,
+          sum(redirect_to_shop) redirect_to_shop,
+          sum(poi_collect) poi_collect,
+          sum(poi_address_click) poi_address_click,
+          sum(luban_order_cnt) luban_order_cnt,
+          sum(luban_order_stat_amount) luban_order_stat_amount,
+          sum(luban_order_roi) luban_order_roi,
+          sum(luban_live_enter_cnt) luban_live_enter_cnt,
+          sum(live_watch_one_minute_count) live_watch_one_minute_count,
+          sum(luban_live_follow_cnt) luban_live_follow_cnt,
+          sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+          sum(luban_live_comment_cnt) luban_live_comment_cnt,
+          sum(luban_live_share_cnt) luban_live_share_cnt,
+          sum(luban_live_gift_cnt) luban_live_gift_cnt,
+          sum(luban_live_gift_amount) luban_live_gift_amount,
+          sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+          sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+          sum(luban_live_pay_order_count) luban_live_pay_order_count,
+          sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+          sum(wechat_login_count) wechat_login_count,
+          sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
+          sum(wechat_first_pay_count) wechat_first_pay_count,
+          sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
+          ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+          ifnull(round(sum(	attribution_wechat_first_pay_30d_count) / sum(	attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+          sum(wechat_pay_amount) wechat_pay_amount,
+          sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+          sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+          sum(phone_effective) phone_effective,
+          sum(total_play) total_play,
+          sum(valid_play) valid_play,
+          ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
+          ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+          sum(play_25_feed_break) play_25_feed_break,
+          sum(play_50_feed_break) play_50_feed_break,
+          sum(play_75_feed_break) play_75_feed_break,
+          sum(play_100_feed_break) play_100_feed_break,
+          ifnull(round(sum(average_play_time_per_play) /{day_count}, 3),0) average_play_time_per_play,
+          ifnull(round(sum(play_over_rate) /{day_count} * 100,3),0) play_over_rate,
+          ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+          sum(wifi_play) wifi_play,
+          ifnull(round(sum(play_duration_sum) /{day_count}, 3),0) play_duration_sum,
+          sum(advanced_creative_phone_click) advanced_creative_phone_click,
+          sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+          sum(advanced_creative_form_click) advanced_creative_form_click,
+          sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+          sum(advanced_creative_form_submit) advanced_creative_form_submit,
+          sum(card_show) card_show,
+          sum(`share`) `share`,
+          sum(`comment`) `comment`,
+          sum(`like`) `like`,
+          sum(follow) follow,
+          sum(home_visited) home_visited,
+          sum(ies_challenge_click) ies_challenge_click,
+          sum(ies_music_click) ies_music_click,
+          sum(location_click) location_click,
+          sum(message_action) message_action,
+          sum(click_landing_page) click_landing_page,
+          sum(click_shopwindow) click_shopwindow,
+          sum(click_website) click_website,
+          sum(click_download) click_download,
+          sum(click_call_dy) click_call_dy,
+          sum(cpc) cpc,
+          sum(cpm) cpm,
+          sum(cpa) cpa,
+          ifnull(round(sum(interact_per_cost) /{day_count}, 3),0) interact_per_cost,
+          ifnull(round(sum(convert_show_rate) /{day_count}, 3),0) convert_show_rate,
+          ifnull(round(sum(play_duration_10s) / sum(total_play) * 100,3),0) play_duration_10s_rate,
+          ifnull(round(sum(play_50_feed_break) / sum(total_play) * 100,3),0) play_50_feed_break_rate,
+          ifnull(round(sum(play_25_feed_break) / sum(total_play) * 100,3),0) play_25_feed_break_rate,
+          ifnull(round(sum(play_duration_5s_rate) /{day_count}, 3),0) play_duration_5s_rate,
+          ifnull(round(sum(play_duration_2s) / sum(total_play) * 100,3),0) play_duration_2s_rate,
+          ifnull(round(sum(average_play_progress) /{day_count}, 3),0) average_play_progress,
+          ifnull(round(sum(play_100_feed_break) / sum(total_play) * 100,3),0) play_100_feed_break_rate,
+          ifnull(round(sum(play_duration_3s) / sum(total_play) * 100,3),0) play_duration_3s_rate,
+          ifnull(round(sum(play_75_feed_break) / sum(total_play) * 100,3),0) play_75_feed_break_rate,
+          sum(play_duration) play_duration,
+          sum(play_duration_3s) play_duration_3s,
+          sum(play_duration_2s) play_duration_2s,
+          sum(play_duration_10s) play_duration_10s,
+          ifnull(round(sum(average_video_play) /{day_count}, 3),0) average_video_play,
+          sum(avg_rank) avg_rank,
+          sum(submit_certification_count) submit_certification_count,
+          sum(approval_count) approval_count,
+          sum(first_order_count) first_rental_order_count,
+          sum(first_rental_order_count) first_order_count,
+          sum(commute_first_pay_count) commute_first_pay_count
 FROM (
          SELECT video.signature,
                 uc.company_id,
@@ -639,21 +443,16 @@ FROM (
          WHERE image_mode IN (
                               'CREATIVE_IMAGE_MODE_VIDEO',
                               'CREATIVE_IMAGE_MODE_VIDEO_VERTICAL',
-                              'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO'
-             )
-           AND stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL {day_count}   DAY),
-                 '%Y%m%d'
-             )
-     ) info
-GROUP BY company_id,
-         company_name,
-         leader_id,
-         org_type,
-         org_code,
-         id,
-         depart_name;
-            """.format(date_time=self.date_time, day_count=self.day_count)
+                              'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO')
+          AND stat_datetime >= date_format( date_sub({date_time}, INTERVAL {day_count} DAY),'%Y%m%d')) info
+          GROUP BY company_id,
+          company_name,
+          leader_id,
+          org_type,
+          org_code,
+          id,
+          depart_name;
+    """.format(date_time=self.date_time, day_count=self.day_count)
             print(sql)
             TidbConn.upsert(conn=self.conn, sql_buff=sql)
             self.conn.commit()

+ 166 - 351
Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyUserReportBusi.py

@@ -26,348 +26,171 @@ SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_
 REPLACE INTO application.app_bytedance_company_user_report_busi_{day_count}d SELECT
 concat(
 date_format(
-date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
-'%Y%m%d'
-),
-'-',
-{date_time}
-) start_end_time,
-company_id,
-company_name,
-org_code,
-org_type,
-dep_id,
-depart_name,
-leader_id,
-trim(leader_name) leader_name,
-count(DISTINCT account_id),
-sum(cost) cost,
-sum(`show`) `show`,
-round(sum(cost) / sum(`show`), 3) avg_show_cost,
-sum(click) click,
-round(sum(cost) / sum(`click`), 3) avg_click_cost,
-round(
-sum(click) / sum(`show`) * 100,
-3
-) ctr,
-sum(`convert`) `convert`,
-round(sum(cost) / sum(`convert`), 3) convert_cost,
-round(
-sum(`convert`) / sum(click) * 100,
-3
-) convert_rate,
-sum(deep_convert) deep_convert,
-round(
-sum(cost) / sum(deep_convert),
-3
-) deep_convert_cost,
-round(
-sum(deep_convert) / sum(`convert`) * 100,
-3
-) deep_convert_rate,
-sum(attribution_convert) attribution_convert,
-round(
-sum(cost) / sum(attribution_convert),
-3
-) attribution_convert_cost,
-sum(attribution_deep_convert) attribution_deep_convert,
-round(
-sum(cost) / sum(attribution_deep_convert),
-3
-) attribution_deep_convert_cost,
-sum(download_start) download_start,
-round(
-sum(cost) / sum(download_start),
-3
-) download_start_cost,
-round(
-sum(download_start) / sum(click),
-3
-) download_start_rate,
-sum(download_finish) download_finish,
-round(
-sum(cost) / sum(download_finish),
-3
-) download_finish_cost,
-round(
-sum(download_finish) / sum(download_start) * 100,
-3
-) download_finish_rate,
-sum(click_install) click_install,
-sum(install_finish) install_finish,
-round(
-sum(cost) / sum(install_finish),
-3
-) install_finish_cost,
-round(
-sum(install_finish) / sum(download_finish) * 100,
-3
-) install_finish_rate,
-sum(active) active,
-round(sum(cost) / sum(active), 3) active_cost,
-round(
-sum(active) / sum(click) * 100,
-3
-) active_rate,
-sum(register) register,
-round(sum(cost) / sum(register), 3) active_register_cost,
-round(
-sum(active_register_rate)/ {day_count} * 100,
-3
-) active_register_rate,
-sum(next_day_open) next_day_open,
-round(
-sum(cost) / sum(next_day_open),
-3
-) next_day_open_cost,
-round(
-sum(next_day_open) / sum(active) * 100,
-3
-) next_day_open_rate,
-sum(
-attribution_next_day_open_cnt
-) attribution_next_day_open_cnt,
-round(
-sum(cost) / sum(
-attribution_next_day_open_cnt
-),
-3
-) attribution_next_day_open_cost,
-round(
-sum(
-attribution_next_day_open_cnt
-) / sum(active) * 100,
-3
-) attribution_next_day_open_rate,
-sum(game_addiction) game_addiction,
-round(
-sum(cost) / sum(game_addiction),
-3
-) game_addiction_cost,
-round(
-sum(game_addiction_rate)/ {day_count} * 100,
-3
-) game_addiction_rate,
-sum(pay_count) pay_count,
-round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-round(
-sum(pay_count) / sum(active) * 100,
-3
-) active_pay_rate,
-sum(loan_completion) loan_completion,
-round(
-sum(cost) / sum(loan_completion),
-3
-) loan_completion_cost,
-round(
-sum(loan_completion) / sum(register) * 100,
-3
-) loan_completion_rate,
-round(sum(pre_loan_credit), 3) pre_loan_credit,
-round(
-sum(cost) / sum(pre_loan_credit),
-3
-) pre_loan_credit_cost,
-sum(loan_credit) loan_credit,
-round(
-sum(cost) / sum(loan_credit),
-3
-) loan_credit_cost,
-round(
-sum(loan_credit) / sum(loan_completion) * 100,
-3
-) loan_credit_rate,
-sum(in_app_uv) in_app_uv,
-sum(in_app_detail_uv) in_app_detail_uv,
-sum(in_app_cart) in_app_cart,
-sum(in_app_pay) in_app_pay,
-sum(in_app_order) in_app_order,
-round(
-sum(
-attribution_game_pay_7d_count
-)/ {day_count},
-3
-) attribution_game_pay_7d_count,
-round(
-sum(
-attribution_game_pay_7d_cost
-)/ {day_count},
-3
-) attribution_game_pay_7d_cost,
-round(
-sum(
-attribution_active_pay_7d_per_count
-)/ {day_count},
-3
-) attribution_active_pay_7d_per_count,
-sum(game_pay_cost) game_pay_cost,
-sum(game_pay_count) game_pay_count,
-sum(phone) phone,
-sum(form) form,
-sum(map_search) map_search,
-sum(button) button,
-sum(`view`) `view`,
-sum(download) download,
-sum(qq) qq,
-sum(lottery) lottery,
-sum(vote) vote,
-sum(message) message,
-sum(redirect) redirect,
-sum(shopping) shopping,
-sum(consult) consult,
-sum(wechat) wechat,
-sum(phone_confirm) phone_confirm,
-sum(phone_connect) phone_connect,
-sum(consult_effective) consult_effective,
-sum(coupon) coupon,
-sum(coupon_single_page) coupon_single_page,
-sum(redirect_to_shop) redirect_to_shop,
-sum(poi_collect) poi_collect,
-sum(poi_address_click) poi_address_click,
-sum(luban_order_cnt) luban_order_cnt,
-sum(luban_order_stat_amount) luban_order_stat_amount,
-sum(luban_order_roi) luban_order_roi,
-sum(luban_live_enter_cnt) luban_live_enter_cnt,
-sum(
-live_watch_one_minute_count
-) live_watch_one_minute_count,
-sum(luban_live_follow_cnt) luban_live_follow_cnt,
-sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
-sum(luban_live_comment_cnt) luban_live_comment_cnt,
-sum(luban_live_share_cnt) luban_live_share_cnt,
-sum(luban_live_gift_cnt) luban_live_gift_cnt,
-sum(luban_live_gift_amount) luban_live_gift_amount,
-sum(
-luban_live_slidecart_click_cnt
-) luban_live_slidecart_click_cnt,
-sum(
-luban_live_click_product_cnt
-) luban_live_click_product_cnt,
-sum(luban_live_pay_order_count) luban_live_pay_order_count,
-sum(
-luban_live_pay_order_stat_cost
-) luban_live_pay_order_stat_cost,
-sum(live_component_click_count) live_component_click_count,
-round(
-sum(cost) / sum(live_component_click_count),
-3
-) live_component_click_cost,
-round(
-sum(live_component_click_count)/ {day_count} * 100,
-3
-) live_component_click_rate,
-sum(wechat_login_count) wechat_login_count,
-sum(
-attribution_wechat_login_30d_count
-) attribution_wechat_login_30d_count,
-round(
-sum(cost) / sum(wechat_login_count),
-3
-) wechat_login_cost,
-round(
-sum(cost) / sum(
-attribution_wechat_login_30d_count
-),
-3
-) attribution_wechat_login_30d_cost,
-sum(wechat_first_pay_count) wechat_first_pay_count,
-sum(
-attribution_wechat_first_pay_30d_count
-) attribution_wechat_first_pay_30d_count,
-round(
-sum(cost) / sum(wechat_first_pay_count),
-3
-) wechat_first_pay_cost,
-round(
-sum(cost) / sum(
-attribution_wechat_first_pay_30d_count
-),
-3
-) attribution_wechat_first_pay_30d_cost,
-round(
-sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-3
-) wechat_first_pay_rate,
-round(
-sum(
-attribution_wechat_first_pay_30d_count
-) / sum(
-attribution_wechat_login_30d_count
-) * 100,
-3
-) attribution_wechat_first_pay_30d_rate,
-sum(wechat_pay_amount) wechat_pay_amount,
-sum(
-attribution_wechat_pay_30d_amount
-) attribution_wechat_pay_30d_amount,
-sum(
-attribution_wechat_pay_30d_roi
-) attribution_wechat_pay_30d_roi,
-sum(phone_effective) phone_effective,
-sum(total_play) total_play,
-sum(valid_play) valid_play,
-round(
-sum(cost) / sum(valid_play),
-3
-) valid_play_cost,
-round(
-sum(valid_play) / sum(`show`) * 100,
-3
-) valid_play_rate,
-sum(play_25_feed_break) play_25_feed_break,
-sum(play_50_feed_break) play_50_feed_break,
-sum(play_75_feed_break) play_75_feed_break,
-sum(play_100_feed_break) play_100_feed_break,
-round(
-sum(average_play_time_per_play)/ {day_count},
-3
-) average_play_time_per_play,
-round(
-sum(play_over_rate)/ {day_count} * 100,
-3
-) play_over_rate,
-round(
-sum(wifi_play) / sum(total_play) * 100,
-3
-) wifi_play_rate,
-sum(wifi_play) wifi_play,
-round(sum(play_duration_sum)/ {day_count}, 3) play_duration_sum,
-sum(
-advanced_creative_phone_click
-) advanced_creative_phone_click,
-sum(
-advanced_creative_counsel_click
-) advanced_creative_counsel_click,
-sum(
-advanced_creative_form_click
-) advanced_creative_form_click,
-sum(
-advanced_creative_coupon_addition
-) advanced_creative_coupon_addition,
-sum(
-advanced_creative_form_submit
-) advanced_creative_form_submit,
-sum(card_show) card_show,
-sum(`share`) `share`,
-sum(`comment`) `comment`,
-sum(`like`) `like`,
-sum(follow) follow,
-sum(home_visited) home_visited,
-sum(ies_challenge_click) ies_challenge_click,
-sum(ies_music_click) ies_music_click,
-sum(location_click) location_click,
-sum(message_action) message_action,
-sum(click_landing_page) click_landing_page,
-sum(click_shopwindow) click_shopwindow,
-sum(click_website) click_website,
-sum(click_download) click_download,
-sum(click_call_dy) click_call_dy,
-sum(submit_certification_count) submit_certification_count,
-sum(approval_count) approval_count,
-sum(first_order_count) first_rental_order_count,
-sum(first_rental_order_count) first_order_count,
-sum(commute_first_pay_count) commute_first_pay_count
-FROM
+date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d'),'-',{date_time})  start_end_time,
+               ifnull(company_id,'-') company_id,
+               company_name,
+               org_code,
+               org_type,
+               dep_id,
+               depart_name,
+               ifnull(leader_id,'-') leader_id,
+               trim(leader_name) leader_name,
+               count(DISTINCT account_id),
+               sum(cost) cost,
+               sum(`show`) `show`,
+               ifnull(round(sum(cost) / sum(`show`), 3) avg_show_cost,
+               sum(click) click,
+               ifnull(round(sum(cost) / sum(`click`), 3) avg_click_cost,
+               ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+               sum(`convert`) `convert`,
+               ifnull(round(sum(cost) / sum(`convert`), 3) convert_cost,
+               ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+               sum(deep_convert) deep_convert,
+               ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
+               ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+               sum(attribution_convert) attribution_convert,
+               ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
+               sum(attribution_deep_convert) attribution_deep_convert,
+               ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
+               sum(download_start) download_start,
+               ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
+               ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
+               sum(download_finish) download_finish,
+               ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
+               ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+               sum(click_install) click_install,
+               sum(install_finish) install_finish,
+               ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
+               ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+               sum(active) active,
+               ifnull(round(sum(cost) / sum(active), 3) active_cost,
+               ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+               sum(register) register,
+               ifnull(round(sum(cost) / sum(register), 3) active_register_cost,
+               ifnull(round(sum(active_register_rate)/ {day_count} * 100,3),0) active_register_rate,
+               sum(next_day_open) next_day_open,
+               ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
+               ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+               sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+               ifnull(round(sum(cost) / sum(attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
+               ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+               sum(game_addiction) game_addiction,
+               ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
+               ifnull(round(sum(game_addiction_rate)/ {day_count} * 100,3),0) game_addiction_rate,
+               sum(pay_count) pay_count,
+               ifnull(round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+               ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+               sum(loan_completion) loan_completion,
+               ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
+               ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+               ifnull(round(sum(pre_loan_credit), 3) pre_loan_credit,
+               ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
+               sum(loan_credit) loan_credit,
+               ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
+               ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+               sum(in_app_uv) in_app_uv,
+               sum(in_app_detail_uv) in_app_detail_uv,
+               sum(in_app_cart) in_app_cart,
+               sum(in_app_pay) in_app_pay,
+               sum(in_app_order) in_app_order,
+               ifnull(round(sum(attribution_game_pay_7d_count)/ {day_count},3),0) attribution_game_pay_7d_count,
+               ifnull(round(sum(attribution_game_pay_7d_cost)/ {day_count},3),0) attribution_game_pay_7d_cost,
+               ifnull(round(sum(attribution_active_pay_7d_per_count)/ {day_count},3),0) attribution_active_pay_7d_per_count,
+               sum(game_pay_cost) game_pay_cost,
+               sum(game_pay_count) game_pay_count,
+               sum(phone) phone,
+               sum(form) form,
+               sum(map_search) map_search,
+               sum(button) button,
+               sum(`view`) `view`,
+               sum(download) download,
+               sum(qq) qq,
+               sum(lottery) lottery,
+               sum(vote) vote,
+               sum(message) message,
+               sum(redirect) redirect,
+               sum(shopping) shopping,
+               sum(consult) consult,
+               sum(wechat) wechat,
+               sum(phone_confirm) phone_confirm,
+               sum(phone_connect) phone_connect,
+               sum(consult_effective) consult_effective,
+               sum(coupon) coupon,
+               sum(coupon_single_page) coupon_single_page,
+               sum(redirect_to_shop) redirect_to_shop,
+               sum(poi_collect) poi_collect,
+               sum(poi_address_click) poi_address_click,
+               sum(luban_order_cnt) luban_order_cnt,
+               sum(luban_order_stat_amount) luban_order_stat_amount,
+               sum(luban_order_roi) luban_order_roi,
+               sum(luban_live_enter_cnt) luban_live_enter_cnt,
+               sum(live_watch_one_minute_count) live_watch_one_minute_count,
+               sum(luban_live_follow_cnt) luban_live_follow_cnt,
+               sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+               sum(luban_live_comment_cnt) luban_live_comment_cnt,
+               sum(luban_live_share_cnt) luban_live_share_cnt,
+               sum(luban_live_gift_cnt) luban_live_gift_cnt,
+               sum(luban_live_gift_amount) luban_live_gift_amount,
+               sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+               sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+               sum(luban_live_pay_order_count) luban_live_pay_order_count,
+               sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+               sum(live_component_click_count) live_component_click_count,
+               ifnull(round(sum(cost) / sum(live_component_click_count),3),0) live_component_click_cost,
+               ifnull(round(sum(live_component_click_count)/ {day_count} * 100,3),0) live_component_click_rate,
+               sum(wechat_login_count) wechat_login_count,
+               sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+               ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
+               ifnull(round(sum(cost) / sum(attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
+               sum(wechat_first_pay_count) wechat_first_pay_count,
+               sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+               ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
+               ifnull(round(sum(cost) / sum(attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
+               ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+               ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+               sum(wechat_pay_amount) wechat_pay_amount,
+               sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+               sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+               sum(phone_effective) phone_effective,
+               sum(total_play) total_play,
+               sum(valid_play) valid_play,
+               ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
+               ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+               sum(play_25_feed_break) play_25_feed_break,
+               sum(play_50_feed_break) play_50_feed_break,
+               sum(play_75_feed_break) play_75_feed_break,
+               sum(play_100_feed_break) play_100_feed_break,
+               ifnull(round(sum(average_play_time_per_play)/ {day_count},3),0) average_play_time_per_play,
+               ifnull(round(sum(play_over_rate)/ {day_count} * 100,3),0) play_over_rate,
+               ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+               sum(wifi_play) wifi_play,
+               ifnull(round(sum(play_duration_sum)/ {day_count}, 3) play_duration_sum,
+               sum(advanced_creative_phone_click) advanced_creative_phone_click,
+               sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+               sum(advanced_creative_form_click) advanced_creative_form_click,
+               sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+               sum(advanced_creative_form_submit) advanced_creative_form_submit,
+               sum(card_show) card_show,
+               sum(`share`) `share`,
+               sum(`comment`) `comment`,
+               sum(`like`) `like`,
+               sum(follow) follow,
+               sum(home_visited) home_visited,
+               sum(ies_challenge_click) ies_challenge_click,
+               sum(ies_music_click) ies_music_click,
+               sum(location_click) location_click,
+               sum(message_action) message_action,
+               sum(click_landing_page) click_landing_page,
+               sum(click_shopwindow) click_shopwindow,
+               sum(click_website) click_website,
+               sum(click_download) click_download,
+               sum(click_call_dy) click_call_dy,
+               sum(submit_certification_count) submit_certification_count,
+               sum(approval_count) approval_count,
+               sum(first_order_count) first_rental_order_count,
+               sum(first_rental_order_count) first_order_count,
+               sum(commute_first_pay_count) commute_first_pay_count
+               FROM
 (
 SELECT
 report.advertiser_id account_id,
@@ -582,15 +405,7 @@ LEFT JOIN `jeecg-boot`.sys_depart pa ON pa.id = de.dep_id
 ) info
 GROUP BY
 company_id,
-company_name,
-org_code,
-org_type,
-dep_id,
-depart_name,
-leader_id,
-trim(leader_name)
-HAVING
-sum(cost) >= 0;
+leader_id;
             """.format(date_time=self.date_time, day_count=self.day_count)
             TidbConn.upsert(conn=self.conn, sql_buff=sql)
             self.conn.commit()

+ 166 - 346
Apietl/bytedance_etl/Q4Task/AppBytedanceCompanyUserReportBusiMonth.py

@@ -23,343 +23,171 @@ class AppBytedanceCompanyUserReportBusiMonth:
             sql = """
 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_company_user_report_busi_m SELECT
-date_format({date_time},'%Y%m') stat_mon,
-company_id,
-company_name,
-org_code,
-org_type,
-dep_id,
-depart_name,
-leader_id,
-trim(leader_name) leader_name,
-count(DISTINCT account_id),
-sum(cost) cost,
-sum(`show`) `show`,
-round(sum(cost) / sum(`show`), 3) avg_show_cost,
-sum(click) click,
-round(sum(cost) / sum(`click`), 3) avg_click_cost,
-round(
-sum(click) / sum(`show`) * 100,
-3
-) ctr,
-sum(`convert`) `convert`,
-round(sum(cost) / sum(`convert`), 3) convert_cost,
-round(
-sum(`convert`) / sum(click) * 100,
-3
-) convert_rate,
-sum(deep_convert) deep_convert,
-round(
-sum(cost) / sum(deep_convert),
-3
-) deep_convert_cost,
-round(
-sum(deep_convert) / sum(`convert`) * 100,
-3
-) deep_convert_rate,
-sum(attribution_convert) attribution_convert,
-round(
-sum(cost) / sum(attribution_convert),
-3
-) attribution_convert_cost,
-sum(attribution_deep_convert) attribution_deep_convert,
-round(
-sum(cost) / sum(attribution_deep_convert),
-3
-) attribution_deep_convert_cost,
-sum(download_start) download_start,
-round(
-sum(cost) / sum(download_start),
-3
-) download_start_cost,
-round(
-sum(download_start) / sum(click),
-3
-) download_start_rate,
-sum(download_finish) download_finish,
-round(
-sum(cost) / sum(download_finish),
-3
-) download_finish_cost,
-round(
-sum(download_finish) / sum(download_start) * 100,
-3
-) download_finish_rate,
-sum(click_install) click_install,
-sum(install_finish) install_finish,
-round(
-sum(cost) / sum(install_finish),
-3
-) install_finish_cost,
-round(
-sum(install_finish) / sum(download_finish) * 100,
-3
-) install_finish_rate,
-sum(active) active,
-round(sum(cost) / sum(active), 3) active_cost,
-round(
-sum(active) / sum(click) * 100,
-3
-) active_rate,
-sum(register) register,
-round(sum(cost) / sum(register), 3) active_register_cost,
-round(
-sum(active_register_rate)/ {day_count} * 100,
-3
-) active_register_rate,
-sum(next_day_open) next_day_open,
-round(
-sum(cost) / sum(next_day_open),
-3
-) next_day_open_cost,
-round(
-sum(next_day_open) / sum(active) * 100,
-3
-) next_day_open_rate,
-sum(
-attribution_next_day_open_cnt
-) attribution_next_day_open_cnt,
-round(
-sum(cost) / sum(
-attribution_next_day_open_cnt
-),
-3
-) attribution_next_day_open_cost,
-round(
-sum(
-attribution_next_day_open_cnt
-) / sum(active) * 100,
-3
-) attribution_next_day_open_rate,
-sum(game_addiction) game_addiction,
-round(
-sum(cost) / sum(game_addiction),
-3
-) game_addiction_cost,
-round(
-sum(game_addiction_rate)/ {day_count} * 100,
-3
-) game_addiction_rate,
-sum(pay_count) pay_count,
-round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-round(
-sum(pay_count) / sum(active) * 100,
-3
-) active_pay_rate,
-sum(loan_completion) loan_completion,
-round(
-sum(cost) / sum(loan_completion),
-3
-) loan_completion_cost,
-round(
-sum(loan_completion) / sum(register) * 100,
-3
-) loan_completion_rate,
-round(sum(pre_loan_credit), 3) pre_loan_credit,
-round(
-sum(cost) / sum(pre_loan_credit),
-3
-) pre_loan_credit_cost,
-sum(loan_credit) loan_credit,
-round(
-sum(cost) / sum(loan_credit),
-3
-) loan_credit_cost,
-round(
-sum(loan_credit) / sum(loan_completion) * 100,
-3
-) loan_credit_rate,
-sum(in_app_uv) in_app_uv,
-sum(in_app_detail_uv) in_app_detail_uv,
-sum(in_app_cart) in_app_cart,
-sum(in_app_pay) in_app_pay,
-sum(in_app_order) in_app_order,
-round(
-sum(
-attribution_game_pay_7d_count
-)/ {day_count},
-3
-) attribution_game_pay_7d_count,
-round(
-sum(
-attribution_game_pay_7d_cost
-)/ {day_count},
-3
-) attribution_game_pay_7d_cost,
-round(
-sum(
-attribution_active_pay_7d_per_count
-)/ {day_count},
-3
-) attribution_active_pay_7d_per_count,
-sum(game_pay_cost) game_pay_cost,
-sum(game_pay_count) game_pay_count,
-sum(phone) phone,
-sum(form) form,
-sum(map_search) map_search,
-sum(button) button,
-sum(`view`) `view`,
-sum(download) download,
-sum(qq) qq,
-sum(lottery) lottery,
-sum(vote) vote,
-sum(message) message,
-sum(redirect) redirect,
-sum(shopping) shopping,
-sum(consult) consult,
-sum(wechat) wechat,
-sum(phone_confirm) phone_confirm,
-sum(phone_connect) phone_connect,
-sum(consult_effective) consult_effective,
-sum(coupon) coupon,
-sum(coupon_single_page) coupon_single_page,
-sum(redirect_to_shop) redirect_to_shop,
-sum(poi_collect) poi_collect,
-sum(poi_address_click) poi_address_click,
-sum(luban_order_cnt) luban_order_cnt,
-sum(luban_order_stat_amount) luban_order_stat_amount,
-sum(luban_order_roi) luban_order_roi,
-sum(luban_live_enter_cnt) luban_live_enter_cnt,
-sum(
-live_watch_one_minute_count
-) live_watch_one_minute_count,
-sum(luban_live_follow_cnt) luban_live_follow_cnt,
-sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
-sum(luban_live_comment_cnt) luban_live_comment_cnt,
-sum(luban_live_share_cnt) luban_live_share_cnt,
-sum(luban_live_gift_cnt) luban_live_gift_cnt,
-sum(luban_live_gift_amount) luban_live_gift_amount,
-sum(
-luban_live_slidecart_click_cnt
-) luban_live_slidecart_click_cnt,
-sum(
-luban_live_click_product_cnt
-) luban_live_click_product_cnt,
-sum(luban_live_pay_order_count) luban_live_pay_order_count,
-sum(
-luban_live_pay_order_stat_cost
-) luban_live_pay_order_stat_cost,
-sum(live_component_click_count) live_component_click_count,
-round(
-sum(cost) / sum(live_component_click_count),
-3
-) live_component_click_cost,
-round(
-sum(live_component_click_count)/ {day_count} * 100,
-3
-) live_component_click_rate,
-sum(wechat_login_count) wechat_login_count,
-sum(
-attribution_wechat_login_30d_count
-) attribution_wechat_login_30d_count,
-round(
-sum(cost) / sum(wechat_login_count),
-3
-) wechat_login_cost,
-round(
-sum(cost) / sum(
-attribution_wechat_login_30d_count
-),
-3
-) attribution_wechat_login_30d_cost,
-sum(wechat_first_pay_count) wechat_first_pay_count,
-sum(
-attribution_wechat_first_pay_30d_count
-) attribution_wechat_first_pay_30d_count,
-round(
-sum(cost) / sum(wechat_first_pay_count),
-3
-) wechat_first_pay_cost,
-round(
-sum(cost) / sum(
-attribution_wechat_first_pay_30d_count
-),
-3
-) attribution_wechat_first_pay_30d_cost,
-round(
-sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-3
-) wechat_first_pay_rate,
-round(
-sum(
-attribution_wechat_first_pay_30d_count
-) / sum(
-attribution_wechat_login_30d_count
-) * 100,
-3
-) attribution_wechat_first_pay_30d_rate,
-sum(wechat_pay_amount) wechat_pay_amount,
-sum(
-attribution_wechat_pay_30d_amount
-) attribution_wechat_pay_30d_amount,
-sum(
-attribution_wechat_pay_30d_roi
-) attribution_wechat_pay_30d_roi,
-sum(phone_effective) phone_effective,
-sum(total_play) total_play,
-sum(valid_play) valid_play,
-round(
-sum(cost) / sum(valid_play),
-3
-) valid_play_cost,
-round(
-sum(valid_play) / sum(`show`) * 100,
-3
-) valid_play_rate,
-sum(play_25_feed_break) play_25_feed_break,
-sum(play_50_feed_break) play_50_feed_break,
-sum(play_75_feed_break) play_75_feed_break,
-sum(play_100_feed_break) play_100_feed_break,
-round(
-sum(average_play_time_per_play)/ {day_count},
-3
-) average_play_time_per_play,
-round(
-sum(play_over_rate)/ {day_count} * 100,
-3
-) play_over_rate,
-round(
-sum(wifi_play) / sum(total_play) * 100,
-3
-) wifi_play_rate,
-sum(wifi_play) wifi_play,
-round(sum(play_duration_sum)/ {day_count}, 3) play_duration_sum,
-sum(
-advanced_creative_phone_click
-) advanced_creative_phone_click,
-sum(
-advanced_creative_counsel_click
-) advanced_creative_counsel_click,
-sum(
-advanced_creative_form_click
-) advanced_creative_form_click,
-sum(
-advanced_creative_coupon_addition
-) advanced_creative_coupon_addition,
-sum(
-advanced_creative_form_submit
-) advanced_creative_form_submit,
-sum(card_show) card_show,
-sum(`share`) `share`,
-sum(`comment`) `comment`,
-sum(`like`) `like`,
-sum(follow) follow,
-sum(home_visited) home_visited,
-sum(ies_challenge_click) ies_challenge_click,
-sum(ies_music_click) ies_music_click,
-sum(location_click) location_click,
-sum(message_action) message_action,
-sum(click_landing_page) click_landing_page,
-sum(click_shopwindow) click_shopwindow,
-sum(click_website) click_website,
-sum(click_download) click_download,
-sum(click_call_dy) click_call_dy,
-sum(submit_certification_count) submit_certification_count,
-sum(approval_count) approval_count,
-sum(first_order_count) first_rental_order_count,
-sum(first_rental_order_count) first_order_count,
-sum(commute_first_pay_count) commute_first_pay_count
-FROM
+               date_format({date_time},'%Y%m') stat_mon,
+               ifnull(company_id,'-') company_id,
+               company_name,
+               org_code,
+               org_type,
+               dep_id,
+               depart_name,
+               ifnull(leader_id,'-') leader_id,
+               trim(leader_name) leader_name,
+               count(DISTINCT account_id),
+               sum(cost) cost,
+               sum(`show`) `show`,
+               ifnull(round(sum(cost) / sum(`show`), 3) avg_show_cost,
+               sum(click) click,
+               ifnull(round(sum(cost) / sum(`click`), 3) avg_click_cost,
+               ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+               sum(`convert`) `convert`,
+               ifnull(round(sum(cost) / sum(`convert`), 3) convert_cost,
+               ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+               sum(deep_convert) deep_convert,
+               ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
+               ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+               sum(attribution_convert) attribution_convert,
+               ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
+               sum(attribution_deep_convert) attribution_deep_convert,
+               ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
+               sum(download_start) download_start,
+               ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
+               ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
+               sum(download_finish) download_finish,
+               ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
+               ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+               sum(click_install) click_install,
+               sum(install_finish) install_finish,
+               ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
+               ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+               sum(active) active,
+               ifnull(round(sum(cost) / sum(active), 3) active_cost,
+               ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+               sum(register) register,
+               ifnull(round(sum(cost) / sum(register), 3) active_register_cost,
+               ifnull(round(sum(active_register_rate)/ {day_count} * 100,3),0) active_register_rate,
+               sum(next_day_open) next_day_open,
+               ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
+               ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+               sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+               ifnull(round(sum(cost) / sum(attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
+               ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+               sum(game_addiction) game_addiction,
+               ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
+               ifnull(round(sum(game_addiction_rate)/ {day_count} * 100,3),0) game_addiction_rate,
+               sum(pay_count) pay_count,
+               ifnull(round(sum(cost) / sum(pay_count), 3) active_pay_cost,
+               ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+               sum(loan_completion) loan_completion,
+               ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
+               ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+               ifnull(round(sum(pre_loan_credit), 3) pre_loan_credit,
+               ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
+               sum(loan_credit) loan_credit,
+               ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
+               ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+               sum(in_app_uv) in_app_uv,
+               sum(in_app_detail_uv) in_app_detail_uv,
+               sum(in_app_cart) in_app_cart,
+               sum(in_app_pay) in_app_pay,
+               sum(in_app_order) in_app_order,
+               ifnull(round(sum(attribution_game_pay_7d_count)/ {day_count},3),0) attribution_game_pay_7d_count,
+               ifnull(round(sum(attribution_game_pay_7d_cost)/ {day_count},3),0) attribution_game_pay_7d_cost,
+               ifnull(round(sum(attribution_active_pay_7d_per_count)/ {day_count},3),0) attribution_active_pay_7d_per_count,
+               sum(game_pay_cost) game_pay_cost,
+               sum(game_pay_count) game_pay_count,
+               sum(phone) phone,
+               sum(form) form,
+               sum(map_search) map_search,
+               sum(button) button,
+               sum(`view`) `view`,
+               sum(download) download,
+               sum(qq) qq,
+               sum(lottery) lottery,
+               sum(vote) vote,
+               sum(message) message,
+               sum(redirect) redirect,
+               sum(shopping) shopping,
+               sum(consult) consult,
+               sum(wechat) wechat,
+               sum(phone_confirm) phone_confirm,
+               sum(phone_connect) phone_connect,
+               sum(consult_effective) consult_effective,
+               sum(coupon) coupon,
+               sum(coupon_single_page) coupon_single_page,
+               sum(redirect_to_shop) redirect_to_shop,
+               sum(poi_collect) poi_collect,
+               sum(poi_address_click) poi_address_click,
+               sum(luban_order_cnt) luban_order_cnt,
+               sum(luban_order_stat_amount) luban_order_stat_amount,
+               sum(luban_order_roi) luban_order_roi,
+               sum(luban_live_enter_cnt) luban_live_enter_cnt,
+               sum(live_watch_one_minute_count) live_watch_one_minute_count,
+               sum(luban_live_follow_cnt) luban_live_follow_cnt,
+               sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+               sum(luban_live_comment_cnt) luban_live_comment_cnt,
+               sum(luban_live_share_cnt) luban_live_share_cnt,
+               sum(luban_live_gift_cnt) luban_live_gift_cnt,
+               sum(luban_live_gift_amount) luban_live_gift_amount,
+               sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+               sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+               sum(luban_live_pay_order_count) luban_live_pay_order_count,
+               sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+               sum(live_component_click_count) live_component_click_count,
+               ifnull(round(sum(cost) / sum(live_component_click_count),3),0) live_component_click_cost,
+               ifnull(round(sum(live_component_click_count)/ {day_count} * 100,3),0) live_component_click_rate,
+               sum(wechat_login_count) wechat_login_count,
+               sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+               ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
+               ifnull(round(sum(cost) / sum(attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
+               sum(wechat_first_pay_count) wechat_first_pay_count,
+               sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+               ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
+               ifnull(round(sum(cost) / sum(attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
+               ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+               ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+               sum(wechat_pay_amount) wechat_pay_amount,
+               sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+               sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+               sum(phone_effective) phone_effective,
+               sum(total_play) total_play,
+               sum(valid_play) valid_play,
+               ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
+               ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+               sum(play_25_feed_break) play_25_feed_break,
+               sum(play_50_feed_break) play_50_feed_break,
+               sum(play_75_feed_break) play_75_feed_break,
+               sum(play_100_feed_break) play_100_feed_break,
+               ifnull(round(sum(average_play_time_per_play)/ {day_count},3),0) average_play_time_per_play,
+               ifnull(round(sum(play_over_rate)/ {day_count} * 100,3),0) play_over_rate,
+               ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+               sum(wifi_play) wifi_play,
+               ifnull(round(sum(play_duration_sum)/ {day_count}, 3) play_duration_sum,
+               sum(advanced_creative_phone_click) advanced_creative_phone_click,
+               sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+               sum(advanced_creative_form_click) advanced_creative_form_click,
+               sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+               sum(advanced_creative_form_submit) advanced_creative_form_submit,
+               sum(card_show) card_show,
+               sum(`share`) `share`,
+               sum(`comment`) `comment`,
+               sum(`like`) `like`,
+               sum(follow) follow,
+               sum(home_visited) home_visited,
+               sum(ies_challenge_click) ies_challenge_click,
+               sum(ies_music_click) ies_music_click,
+               sum(location_click) location_click,
+               sum(message_action) message_action,
+               sum(click_landing_page) click_landing_page,
+               sum(click_shopwindow) click_shopwindow,
+               sum(click_website) click_website,
+               sum(click_download) click_download,
+               sum(click_call_dy) click_call_dy,
+               sum(submit_certification_count) submit_certification_count,
+               sum(approval_count) approval_count,
+               sum(first_order_count) first_rental_order_count,
+               sum(first_rental_order_count) first_order_count,
+               sum(commute_first_pay_count) commute_first_pay_count
+               FROM
 (
 SELECT
 report.advertiser_id account_id,
@@ -574,15 +402,7 @@ LEFT JOIN `jeecg-boot`.sys_depart pa ON pa.id = de.dep_id
 ) info
 GROUP BY
 company_id,
-company_name,
-org_code,
-org_type,
-dep_id,
-depart_name,
-leader_id,
-trim(leader_name)
-HAVING
-sum(cost) >= 0;
+leader_id;
             """.format(date_time=self.date_time, day_count=self.day_count)
             TidbConn.upsert(conn=self.conn, sql_buff=sql)
             self.conn.commit()

+ 179 - 381
Apietl/bytedance_etl/Q4Task/AppBytedanceImageReportBusi.py

@@ -28,7 +28,7 @@ group by project_id """
                 try:
                     sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_image_report_busi_{day_count}d
-SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d'),'-',{date_time})           time,
+SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d'),'-',{date_time}) time,,
        report.account_id,
        #'账户ID'
        report.material_id,
@@ -236,379 +236,182 @@ SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY)
        report.commute_first_pay_count,
        video.`image_url`,
        ''
-FROM (
-         SELECT advertiser_id                        account_id,
+FROM ( SELECT advertiser_id    account_id,
                 material_id,
                 image_mode,
                 inventory,
-                sum(cost)                            cost,
-                sum(`show`)                          `show`,
-                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-                sum(click)                           click,
-                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-                round(
-                        sum(click) / sum(`show`) * 100,
-                        3
-                    )                                ctr,
-                sum(`convert`)                       `convert`,
-                round(sum(cost) / sum(`convert`), 3) convert_cost,
-                round(
-                        sum(`convert`) / sum(click) * 100,
-                        3
-                    )                                convert_rate,
-                sum(deep_convert)                    deep_convert,
-                round(
-                        sum(cost) / sum(deep_convert),
-                        3
-                    )                                deep_convert_cost,
-                round(
-                        sum(deep_convert) / sum(`convert`) * 100,
-                        3
-                    )                                deep_convert_rate,
-                sum(attribution_convert)             attribution_convert,
-                round(
-                        sum(cost) / sum(attribution_convert),
-                        3
-                    )                                attribution_convert_cost,
-                sum(attribution_deep_convert)        attribution_deep_convert,
-                round(
-                        sum(cost) / sum(attribution_deep_convert),
-                        3
-                    )                                attribution_deep_convert_cost,
-                sum(download_start)                  download_start,
-                round(
-                        sum(cost) / sum(download_start),
-                        3
-                    )                                download_start_cost,
-                round(
-                        sum(download_start) / sum(click),
-                        3
-                    )                                download_start_rate,
-                sum(download_finish)                 download_finish,
-                round(
-                        sum(cost) / sum(download_finish),
-                        3
-                    )                                download_finish_cost,
-                round(
-                        sum(download_finish) / sum(download_start) * 100,
-                        3
-                    )                                download_finish_rate,
-                sum(click_install)                   click_install,
-                sum(install_finish)                  install_finish,
-                round(
-                        sum(cost) / sum(install_finish),
-                        3
-                    )                                install_finish_cost,
-                round(
-                        sum(install_finish) / sum(download_finish) * 100,
-                        3
-                    )                                install_finish_rate,
-                sum(active)                          active,
-                round(sum(cost) / sum(active), 3)    active_cost,
-                round(
-                        sum(active) / sum(click) * 100,
-                        3
-                    )                                active_rate,
-                sum(register)                        register,
-                round(sum(cost) / sum(register), 3)  active_register_cost,
-                round(
-                        sum(active_register_rate) / {day_count} * 100,
-                        3
-                    )                                active_register_rate,
-                sum(active_pay_amount)               active_pay_amount,
-                sum(next_day_open)                   next_day_open,
-                round(
-                        sum(cost) / sum(next_day_open),
-                        3
-                    )                                next_day_open_cost,
-                round(
-                        sum(next_day_open) / sum(active) * 100,
-                        3
-                    )                                next_day_open_rate,
-                sum(
-                        attribution_next_day_open_cnt
-                    )                                attribution_next_day_open_cnt,
-                round(
-                            sum(cost) / sum(
-                                attribution_next_day_open_cnt
-                            ),
-                            3
-                    )                                attribution_next_day_open_cost,
-                round(
-                                sum(
-                                        attribution_next_day_open_cnt
-                                    ) / sum(active) * 100,
-                                3
-                    )                                attribution_next_day_open_rate,
-                sum(game_addiction)                  game_addiction,
-                round(
-                        sum(cost) / sum(game_addiction),
-                        3
-                    )                                game_addiction_cost,
-                round(
-                        sum(game_addiction_rate) / {day_count} * 100,
-                        3
-                    )                                game_addiction_rate,
-                sum(pay_count)                       pay_count,
-                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-                round(
-                        sum(pay_count) / sum(active) * 100,
-                        3
-                    )                                active_pay_rate,
-                sum(loan_completion)                 loan_completion,
-                round(
-                        sum(cost) / sum(loan_completion),
-                        3
-                    )                                loan_completion_cost,
-                round(
-                        sum(loan_completion) / sum(register) * 100,
-                        3
-                    )                                loan_completion_rate,
-                round(sum(pre_loan_credit), 3)       pre_loan_credit,
-                round(
-                        sum(cost) / sum(pre_loan_credit),
-                        3
-                    )                                pre_loan_credit_cost,
-                sum(loan_credit)                     loan_credit,
-                round(
-                        sum(cost) / sum(loan_credit),
-                        3
-                    )                                loan_credit_cost,
-                round(
-                        sum(loan_credit) / sum(loan_completion) * 100,
-                        3
-                    )                                loan_credit_rate,
-                sum(in_app_uv)                       in_app_uv,
-                sum(in_app_detail_uv)                in_app_detail_uv,
-                sum(in_app_cart)                     in_app_cart,
-                sum(in_app_pay)                      in_app_pay,
-                sum(in_app_order)                    in_app_order,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_count
-                                ) / {day_count},
-                            3
-                    )                                attribution_game_pay_7d_count,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_cost
-                                ) / {day_count},
-                            3
-                    )                                attribution_game_pay_7d_cost,
-                round(
-                            sum(
-                                    attribution_active_pay_7d_per_count
-                                ) / {day_count},
-                            3
-                    )                                attribution_active_pay_7d_per_count,
-                sum(game_pay_cost)                   game_pay_cost,
-                sum(game_pay_count)                  game_pay_count,
-                sum(phone)                           phone,
-                sum(form)                            form,
-                sum(map_search)                      map_search,
-                sum(button)                          button,
-                sum(`view`)                          `view`,
-                sum(download)                        download,
-                sum(qq)                              qq,
-                sum(lottery)                         lottery,
-                sum(vote)                            vote,
-                sum(message)                         message,
-                sum(redirect)                        redirect,
-                sum(shopping)                        shopping,
-                sum(consult)                         consult,
-                sum(wechat)                          wechat,
-                sum(phone_confirm)                   phone_confirm,
-                sum(phone_connect)                   phone_connect,
-                sum(consult_effective)               consult_effective,
-                sum(coupon)                          coupon,
-                sum(coupon_single_page)              coupon_single_page,
-                sum(redirect_to_shop)                redirect_to_shop,
-                sum(poi_collect)                     poi_collect,
-                sum(poi_address_click)               poi_address_click,
-                sum(luban_order_cnt)                 luban_order_cnt,
-                sum(luban_order_stat_amount)         luban_order_stat_amount,
-                sum(luban_order_roi)                 luban_order_roi,
-                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-                sum(
-                        live_watch_one_minute_count
-                    )                                live_watch_one_minute_count,
-                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-                sum(luban_live_share_cnt)            luban_live_share_cnt,
-                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-                sum(luban_live_gift_amount)          luban_live_gift_amount,
-                sum(
-                        luban_live_slidecart_click_cnt
-                    )                                luban_live_slidecart_click_cnt,
-                sum(
-                        luban_live_click_product_cnt
-                    )                                luban_live_click_product_cnt,
-                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-                sum(
-                        luban_live_pay_order_stat_cost
-                    )                                luban_live_pay_order_stat_cost,
-                sum(wechat_login_count)              wechat_login_count,
-                sum(
-                        attribution_wechat_login_30d_count
-                    )                                attribution_wechat_login_30d_count,
-                round(
-                        sum(cost) / sum(wechat_login_count),
-                        3
-                    )                                wechat_login_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_login_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_login_30d_cost,
-                sum(wechat_first_pay_count)          wechat_first_pay_count,
-                sum(
-                        attribution_wechat_first_pay_30d_count
-                    )                                attribution_wechat_first_pay_30d_count,
-                round(
-                        sum(cost) / sum(wechat_first_pay_count),
-                        3
-                    )                                wechat_first_pay_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_first_pay_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_first_pay_30d_cost,
-                round(
-                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-                        3
-                    )                                wechat_first_pay_rate,
-                round(
-                                sum(
-                                        attribution_wechat_first_pay_30d_count
-                                    ) / sum(
-                                        attribution_wechat_login_30d_count
-                                    ) * 100,
-                                3
-                    )                                attribution_wechat_first_pay_30d_rate,
-                sum(wechat_pay_amount)               wechat_pay_amount,
-                sum(
-                        attribution_wechat_pay_30d_amount
-                    )                                attribution_wechat_pay_30d_amount,
-                sum(
-                        attribution_wechat_pay_30d_roi
-                    )                                attribution_wechat_pay_30d_roi,
-                sum(phone_effective)                 phone_effective,
-                sum(total_play)                      total_play,
-                sum(valid_play)                      valid_play,
-                round(
-                        sum(cost) / sum(valid_play),
-                        3
-                    )                                valid_play_cost,
-                round(
-                        sum(valid_play) / sum(`show`) * 100,
-                        3
-                    )                                valid_play_rate,
-                sum(play_25_feed_break)              play_25_feed_break,
-                sum(play_50_feed_break)              play_50_feed_break,
-                sum(play_75_feed_break)              play_75_feed_break,
-                sum(play_100_feed_break)             play_100_feed_break,
-                round(
-                        sum(average_play_time_per_play) / {day_count},
-                        3
-                    )                                average_play_time_per_play,
-                round(
-                        sum(play_over_rate) / {day_count} * 100,
-                        3
-                    )                                play_over_rate,
-                round(
-                        sum(wifi_play) / sum(total_play) * 100,
-                        3
-                    )                                wifi_play_rate,
-                sum(wifi_play)                       wifi_play,
-                round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-                sum(
-                        advanced_creative_phone_click
-                    )                                advanced_creative_phone_click,
-                sum(
-                        advanced_creative_counsel_click
-                    )                                advanced_creative_counsel_click,
-                sum(
-                        advanced_creative_form_click
-                    )                                advanced_creative_form_click,
-                sum(
-                        advanced_creative_coupon_addition
-                    )                                advanced_creative_coupon_addition,
-                sum(
-                        advanced_creative_form_submit
-                    )                                advanced_creative_form_submit,
-                sum(card_show)                       card_show,
-                sum(`share`)                         `share`,
-                sum(`comment`)                       `comment`,
-                sum(`like`)                          `like`,
-                sum(follow)                          follow,
-                sum(home_visited)                    home_visited,
-                sum(ies_challenge_click)             ies_challenge_click,
-                sum(ies_music_click)                 ies_music_click,
-                sum(location_click)                  location_click,
-                sum(message_action)                  message_action,
-                sum(click_landing_page)              click_landing_page,
-                sum(click_shopwindow)                click_shopwindow,
-                sum(click_website)                   click_website,
-                sum(click_download)                  click_download,
-                sum(click_call_dy)                   click_call_dy,
-                sum(cpc)                             cpc,
-                sum(cpm)                             cpm,
-                sum(cpa)                             cpa,
-                round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
-                round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
-                round(
-                        sum(round(play_duration_10s)) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_10s_rate,
-                round(
-                        sum(play_50_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_50_feed_break_rate,
-                round(
-                        sum(play_25_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_25_feed_break_rate,
-                round(
-                        sum(play_duration_5s_rate) / {day_count},
-                        3
-                    )                                play_duration_5s_rate,
-                round(
-                        sum(play_duration_2s) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_2s_rate,
-                round(
-                        sum(average_play_progress) / {day_count},
-                        3
-                    )                                average_play_progress,
-                round(
-                        sum(play_100_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_100_feed_break_rate,
-                round(
-                        sum(play_duration_3s) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_3s_rate,
-                round(
-                        sum(play_75_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_75_feed_break_rate,
-                sum(play_duration)                   play_duration,
-                sum(play_duration_3s)                play_duration_3s,
-                sum(play_duration_2s)                play_duration_2s,
-                sum(play_duration_10s)               play_duration_10s,
-                round(
-                        sum(average_video_play) / {day_count},
-                        3
-                    )                                average_video_play,
-                sum(avg_rank)                        avg_rank,
-                sum(submit_certification_count)      submit_certification_count,
-                sum(approval_count)                  approval_count,
-                sum(first_order_count)               first_rental_order_count,
-                sum(first_rental_order_count)        first_order_count,
-                sum(commute_first_pay_count)         commute_first_pay_count
+          sum(cost) cost,
+          sum(`show`) `show`,
+          ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+          sum(click) click,
+          ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+          ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+          sum(`convert`) `convert`,
+          ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+          ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+          sum(deep_convert) deep_convert,
+          ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
+          ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+          sum(attribution_convert) attribution_convert,
+          ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
+          sum(attribution_deep_convert) attribution_deep_convert,
+          ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
+          sum(download_start) download_start,
+          ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
+          ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
+          sum(download_finish) download_finish,
+          ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
+          ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+          sum(click_install) click_install,
+          sum(install_finish) install_finish,
+          ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
+          ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+          sum(active) active,
+          ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+          ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+          sum(register) register,
+          ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+          ifnull(round(sum(active_register_rate) /{day_count} * 100,3),0) active_register_rate,
+          sum(active_pay_amount) active_pay_amount,
+          sum(next_day_open) next_day_open,
+          ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
+          ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+          sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+          ifnull(round(sum(cost) / sum(	attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
+          ifnull(round(sum(	attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+          sum(game_addiction) game_addiction,
+          ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
+          ifnull(round(sum(game_addiction_rate) /{day_count} * 100,3),0) game_addiction_rate,
+          sum(pay_count) pay_count,
+          ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+          ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+          sum(loan_completion) loan_completion,
+          ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
+          ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+          ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+          ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
+          sum(loan_credit) loan_credit,
+          ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
+          ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+          sum(in_app_uv) in_app_uv,
+          sum(in_app_detail_uv) in_app_detail_uv,
+          sum(in_app_cart) in_app_cart,
+          sum(in_app_pay) in_app_pay,
+          sum(in_app_order) in_app_order,
+          ifnull(round(sum(	attribution_game_pay_7d_count) /{day_count}, 3),0) attribution_game_pay_7d_count,
+          ifnull(round(sum(	attribution_game_pay_7d_cost) /{day_count}, 3),0) attribution_game_pay_7d_cost,
+          ifnull(round(sum(	attribution_active_pay_7d_per_count) /{day_count}, 3),0) attribution_active_pay_7d_per_count,
+          sum(game_pay_cost) game_pay_cost,
+          sum(game_pay_count) game_pay_count,
+          sum(phone) phone,
+          sum(form) form,
+          sum(map_search) map_search,
+          sum(button) button,
+          sum(`view`) `view`,
+          sum(download) download,
+          sum(qq) qq,
+          sum(lottery) lottery,
+          sum(vote) vote,
+          sum(message) message,
+          sum(redirect) redirect,
+          sum(shopping) shopping,
+          sum(consult) consult,
+          sum(wechat) wechat,
+          sum(phone_confirm) phone_confirm,
+          sum(phone_connect) phone_connect,
+          sum(consult_effective) consult_effective,
+          sum(coupon) coupon,
+          sum(coupon_single_page) coupon_single_page,
+          sum(redirect_to_shop) redirect_to_shop,
+          sum(poi_collect) poi_collect,
+          sum(poi_address_click) poi_address_click,
+          sum(luban_order_cnt) luban_order_cnt,
+          sum(luban_order_stat_amount) luban_order_stat_amount,
+          sum(luban_order_roi) luban_order_roi,
+          sum(luban_live_enter_cnt) luban_live_enter_cnt,
+          sum(live_watch_one_minute_count) live_watch_one_minute_count,
+          sum(luban_live_follow_cnt) luban_live_follow_cnt,
+          sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+          sum(luban_live_comment_cnt) luban_live_comment_cnt,
+          sum(luban_live_share_cnt) luban_live_share_cnt,
+          sum(luban_live_gift_cnt) luban_live_gift_cnt,
+          sum(luban_live_gift_amount) luban_live_gift_amount,
+          sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+          sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+          sum(luban_live_pay_order_count) luban_live_pay_order_count,
+          sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+          sum(wechat_login_count) wechat_login_count,
+          sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
+          sum(wechat_first_pay_count) wechat_first_pay_count,
+          sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
+          ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+          ifnull(round(sum(	attribution_wechat_first_pay_30d_count) / sum(	attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+          sum(wechat_pay_amount) wechat_pay_amount,
+          sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+          sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+          sum(phone_effective) phone_effective,
+          sum(total_play) total_play,
+          sum(valid_play) valid_play,
+          ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
+          ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+          sum(play_25_feed_break) play_25_feed_break,
+          sum(play_50_feed_break) play_50_feed_break,
+          sum(play_75_feed_break) play_75_feed_break,
+          sum(play_100_feed_break) play_100_feed_break,
+          ifnull(round(sum(average_play_time_per_play) /{day_count}, 3),0) average_play_time_per_play,
+          ifnull(round(sum(play_over_rate) /{day_count} * 100,3),0) play_over_rate,
+          ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+          sum(wifi_play) wifi_play,
+          ifnull(round(sum(play_duration_sum) /{day_count}, 3),0) play_duration_sum,
+          sum(advanced_creative_phone_click) advanced_creative_phone_click,
+          sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+          sum(advanced_creative_form_click) advanced_creative_form_click,
+          sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+          sum(advanced_creative_form_submit) advanced_creative_form_submit,
+          sum(card_show) card_show,
+          sum(`share`) `share`,
+          sum(`comment`) `comment`,
+          sum(`like`) `like`,
+          sum(follow) follow,
+          sum(home_visited) home_visited,
+          sum(ies_challenge_click) ies_challenge_click,
+          sum(ies_music_click) ies_music_click,
+          sum(location_click) location_click,
+          sum(message_action) message_action,
+          sum(click_landing_page) click_landing_page,
+          sum(click_shopwindow) click_shopwindow,
+          sum(click_website) click_website,
+          sum(click_download) click_download,
+          sum(click_call_dy) click_call_dy,
+          sum(cpc) cpc,
+          sum(cpm) cpm,
+          sum(cpa) cpa,
+          ifnull(round(sum(interact_per_cost) /{day_count}, 3),0) interact_per_cost,
+          ifnull(round(sum(convert_show_rate) /{day_count}, 3),0) convert_show_rate,
+          ifnull(round(sum(play_duration_10s) / sum(total_play) * 100,3),0) play_duration_10s_rate,
+          ifnull(round(sum(play_50_feed_break) / sum(total_play) * 100,3),0) play_50_feed_break_rate,
+          ifnull(round(sum(play_25_feed_break) / sum(total_play) * 100,3),0) play_25_feed_break_rate,
+          ifnull(round(sum(play_duration_5s_rate) /{day_count}, 3),0) play_duration_5s_rate,
+          ifnull(round(sum(play_duration_2s) / sum(total_play) * 100,3),0) play_duration_2s_rate,
+          ifnull(round(sum(average_play_progress) /{day_count}, 3),0) average_play_progress,
+          ifnull(round(sum(play_100_feed_break) / sum(total_play) * 100,3),0) play_100_feed_break_rate,
+          ifnull(round(sum(play_duration_3s) / sum(total_play) * 100,3),0) play_duration_3s_rate,
+          ifnull(round(sum(play_75_feed_break) / sum(total_play) * 100,3),0) play_75_feed_break_rate,
+          sum(play_duration) play_duration,
+          sum(play_duration_3s) play_duration_3s,
+          sum(play_duration_2s) play_duration_2s,
+          sum(play_duration_10s) play_duration_10s,
+          ifnull(round(sum(average_video_play) /{day_count}, 3),0) average_video_play,
+          sum(avg_rank) avg_rank,
+          sum(submit_certification_count) submit_certification_count,
+          sum(approval_count) approval_count,
+          sum(first_order_count) first_rental_order_count,
+          sum(first_rental_order_count) first_order_count,
+          sum(commute_first_pay_count) commute_first_pay_count
          FROM media_api.bytedance_material_report_daily zhubiao
          WHERE image_mode IN (
     'CREATIVE_IMAGE_MODE_SMALL',
@@ -618,18 +421,13 @@ FROM (
     'CREATIVE_IMAGE_MODE_GIF',
     'TOUTIAO_SEARCH_AD_IMAGE',
     'SEARCH_AD_SMALL_IMAGE',
-    'CREATIVE_IMAGE_MODE_UNION_SPLASH'
-             )
-           AND stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
-                 '%Y%m%d'
-             )
-         GROUP BY advertiser_id,
+    'CREATIVE_IMAGE_MODE_UNION_SPLASH')
+       AND stat_datetime >= date_format(date_sub({date_time}, INTERVAL ({day_count} -1)  DAY),'%Y%m%d')
+       GROUP BY advertiser_id,
                   material_id,
                   image_mode,
-                  inventory
-     ) report
-        LEFT JOIN (select advertiser_id,signature,material_id,filename,image_url
+                  inventory) report
+LEFT JOIN (select advertiser_id,signature,material_id,filename,image_url
 from  `media_api`.bytedance_file_image_get group by advertiser_id,signature,material_id,filename,image_url)  video 
 ON report.account_id = video.advertiser_id AND report.material_id = video.material_id
           LEFT JOIN `jeecg-boot`.ctop_user_allocation cua

+ 181 - 384
Apietl/bytedance_etl/Q4Task/AppBytedanceImageReportBusiMonth.py

@@ -29,7 +29,7 @@ group by project_id """
                     sql = """SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_image_report_busi_m
 SELECT date_format({date_time},'%Y%m')          stat_non,
-       report.account_id,
+     report.account_id,
        #'账户ID'
        report.material_id,
        #头条素材id
@@ -61,7 +61,7 @@ SELECT date_format({date_time},'%Y%m')          stat_non,
        #机构编码
        video.signature    signature,
        #素材id
-       video.filename AS    video_name,
+       video.filename  as video_name,
        report.cost,
        report.`show`,
        report.avg_show_cost,
@@ -236,379 +236,182 @@ SELECT date_format({date_time},'%Y%m')          stat_non,
        report.commute_first_pay_count,
        video.`image_url`,
        ''
-FROM (
-         SELECT advertiser_id                        account_id,
+FROM ( SELECT advertiser_id    account_id,
                 material_id,
                 image_mode,
                 inventory,
-                sum(cost)                            cost,
-                sum(`show`)                          `show`,
-                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-                sum(click)                           click,
-                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-                round(
-                        sum(click) / sum(`show`) * 100,
-                        3
-                    )                                ctr,
-                sum(`convert`)                       `convert`,
-                round(sum(cost) / sum(`convert`), 3) convert_cost,
-                round(
-                        sum(`convert`) / sum(click) * 100,
-                        3
-                    )                                convert_rate,
-                sum(deep_convert)                    deep_convert,
-                round(
-                        sum(cost) / sum(deep_convert),
-                        3
-                    )                                deep_convert_cost,
-                round(
-                        sum(deep_convert) / sum(`convert`) * 100,
-                        3
-                    )                                deep_convert_rate,
-                sum(attribution_convert)             attribution_convert,
-                round(
-                        sum(cost) / sum(attribution_convert),
-                        3
-                    )                                attribution_convert_cost,
-                sum(attribution_deep_convert)        attribution_deep_convert,
-                round(
-                        sum(cost) / sum(attribution_deep_convert),
-                        3
-                    )                                attribution_deep_convert_cost,
-                sum(download_start)                  download_start,
-                round(
-                        sum(cost) / sum(download_start),
-                        3
-                    )                                download_start_cost,
-                round(
-                        sum(download_start) / sum(click),
-                        3
-                    )                                download_start_rate,
-                sum(download_finish)                 download_finish,
-                round(
-                        sum(cost) / sum(download_finish),
-                        3
-                    )                                download_finish_cost,
-                round(
-                        sum(download_finish) / sum(download_start) * 100,
-                        3
-                    )                                download_finish_rate,
-                sum(click_install)                   click_install,
-                sum(install_finish)                  install_finish,
-                round(
-                        sum(cost) / sum(install_finish),
-                        3
-                    )                                install_finish_cost,
-                round(
-                        sum(install_finish) / sum(download_finish) * 100,
-                        3
-                    )                                install_finish_rate,
-                sum(active)                          active,
-                round(sum(cost) / sum(active), 3)    active_cost,
-                round(
-                        sum(active) / sum(click) * 100,
-                        3
-                    )                                active_rate,
-                sum(register)                        register,
-                round(sum(cost) / sum(register), 3)  active_register_cost,
-                round(
-                        sum(active_register_rate) / {day_count} * 100,
-                        3
-                    )                                active_register_rate,
-                sum(active_pay_amount)               active_pay_amount,
-                sum(next_day_open)                   next_day_open,
-                round(
-                        sum(cost) / sum(next_day_open),
-                        3
-                    )                                next_day_open_cost,
-                round(
-                        sum(next_day_open) / sum(active) * 100,
-                        3
-                    )                                next_day_open_rate,
-                sum(
-                        attribution_next_day_open_cnt
-                    )                                attribution_next_day_open_cnt,
-                round(
-                            sum(cost) / sum(
-                                attribution_next_day_open_cnt
-                            ),
-                            3
-                    )                                attribution_next_day_open_cost,
-                round(
-                                sum(
-                                        attribution_next_day_open_cnt
-                                    ) / sum(active) * 100,
-                                3
-                    )                                attribution_next_day_open_rate,
-                sum(game_addiction)                  game_addiction,
-                round(
-                        sum(cost) / sum(game_addiction),
-                        3
-                    )                                game_addiction_cost,
-                round(
-                        sum(game_addiction_rate) / {day_count} * 100,
-                        3
-                    )                                game_addiction_rate,
-                sum(pay_count)                       pay_count,
-                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-                round(
-                        sum(pay_count) / sum(active) * 100,
-                        3
-                    )                                active_pay_rate,
-                sum(loan_completion)                 loan_completion,
-                round(
-                        sum(cost) / sum(loan_completion),
-                        3
-                    )                                loan_completion_cost,
-                round(
-                        sum(loan_completion) / sum(register) * 100,
-                        3
-                    )                                loan_completion_rate,
-                round(sum(pre_loan_credit), 3)       pre_loan_credit,
-                round(
-                        sum(cost) / sum(pre_loan_credit),
-                        3
-                    )                                pre_loan_credit_cost,
-                sum(loan_credit)                     loan_credit,
-                round(
-                        sum(cost) / sum(loan_credit),
-                        3
-                    )                                loan_credit_cost,
-                round(
-                        sum(loan_credit) / sum(loan_completion) * 100,
-                        3
-                    )                                loan_credit_rate,
-                sum(in_app_uv)                       in_app_uv,
-                sum(in_app_detail_uv)                in_app_detail_uv,
-                sum(in_app_cart)                     in_app_cart,
-                sum(in_app_pay)                      in_app_pay,
-                sum(in_app_order)                    in_app_order,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_count
-                                ) / {day_count},
-                            3
-                    )                                attribution_game_pay_7d_count,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_cost
-                                ) / {day_count},
-                            3
-                    )                                attribution_game_pay_7d_cost,
-                round(
-                            sum(
-                                    attribution_active_pay_7d_per_count
-                                ) / {day_count},
-                            3
-                    )                                attribution_active_pay_7d_per_count,
-                sum(game_pay_cost)                   game_pay_cost,
-                sum(game_pay_count)                  game_pay_count,
-                sum(phone)                           phone,
-                sum(form)                            form,
-                sum(map_search)                      map_search,
-                sum(button)                          button,
-                sum(`view`)                          `view`,
-                sum(download)                        download,
-                sum(qq)                              qq,
-                sum(lottery)                         lottery,
-                sum(vote)                            vote,
-                sum(message)                         message,
-                sum(redirect)                        redirect,
-                sum(shopping)                        shopping,
-                sum(consult)                         consult,
-                sum(wechat)                          wechat,
-                sum(phone_confirm)                   phone_confirm,
-                sum(phone_connect)                   phone_connect,
-                sum(consult_effective)               consult_effective,
-                sum(coupon)                          coupon,
-                sum(coupon_single_page)              coupon_single_page,
-                sum(redirect_to_shop)                redirect_to_shop,
-                sum(poi_collect)                     poi_collect,
-                sum(poi_address_click)               poi_address_click,
-                sum(luban_order_cnt)                 luban_order_cnt,
-                sum(luban_order_stat_amount)         luban_order_stat_amount,
-                sum(luban_order_roi)                 luban_order_roi,
-                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-                sum(
-                        live_watch_one_minute_count
-                    )                                live_watch_one_minute_count,
-                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-                sum(luban_live_share_cnt)            luban_live_share_cnt,
-                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-                sum(luban_live_gift_amount)          luban_live_gift_amount,
-                sum(
-                        luban_live_slidecart_click_cnt
-                    )                                luban_live_slidecart_click_cnt,
-                sum(
-                        luban_live_click_product_cnt
-                    )                                luban_live_click_product_cnt,
-                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-                sum(
-                        luban_live_pay_order_stat_cost
-                    )                                luban_live_pay_order_stat_cost,
-                sum(wechat_login_count)              wechat_login_count,
-                sum(
-                        attribution_wechat_login_30d_count
-                    )                                attribution_wechat_login_30d_count,
-                round(
-                        sum(cost) / sum(wechat_login_count),
-                        3
-                    )                                wechat_login_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_login_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_login_30d_cost,
-                sum(wechat_first_pay_count)          wechat_first_pay_count,
-                sum(
-                        attribution_wechat_first_pay_30d_count
-                    )                                attribution_wechat_first_pay_30d_count,
-                round(
-                        sum(cost) / sum(wechat_first_pay_count),
-                        3
-                    )                                wechat_first_pay_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_first_pay_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_first_pay_30d_cost,
-                round(
-                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-                        3
-                    )                                wechat_first_pay_rate,
-                round(
-                                sum(
-                                        attribution_wechat_first_pay_30d_count
-                                    ) / sum(
-                                        attribution_wechat_login_30d_count
-                                    ) * 100,
-                                3
-                    )                                attribution_wechat_first_pay_30d_rate,
-                sum(wechat_pay_amount)               wechat_pay_amount,
-                sum(
-                        attribution_wechat_pay_30d_amount
-                    )                                attribution_wechat_pay_30d_amount,
-                sum(
-                        attribution_wechat_pay_30d_roi
-                    )                                attribution_wechat_pay_30d_roi,
-                sum(phone_effective)                 phone_effective,
-                sum(total_play)                      total_play,
-                sum(valid_play)                      valid_play,
-                round(
-                        sum(cost) / sum(valid_play),
-                        3
-                    )                                valid_play_cost,
-                round(
-                        sum(valid_play) / sum(`show`) * 100,
-                        3
-                    )                                valid_play_rate,
-                sum(play_25_feed_break)              play_25_feed_break,
-                sum(play_50_feed_break)              play_50_feed_break,
-                sum(play_75_feed_break)              play_75_feed_break,
-                sum(play_100_feed_break)             play_100_feed_break,
-                round(
-                        sum(average_play_time_per_play) / {day_count},
-                        3
-                    )                                average_play_time_per_play,
-                round(
-                        sum(play_over_rate) / {day_count} * 100,
-                        3
-                    )                                play_over_rate,
-                round(
-                        sum(wifi_play) / sum(total_play) * 100,
-                        3
-                    )                                wifi_play_rate,
-                sum(wifi_play)                       wifi_play,
-                round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-                sum(
-                        advanced_creative_phone_click
-                    )                                advanced_creative_phone_click,
-                sum(
-                        advanced_creative_counsel_click
-                    )                                advanced_creative_counsel_click,
-                sum(
-                        advanced_creative_form_click
-                    )                                advanced_creative_form_click,
-                sum(
-                        advanced_creative_coupon_addition
-                    )                                advanced_creative_coupon_addition,
-                sum(
-                        advanced_creative_form_submit
-                    )                                advanced_creative_form_submit,
-                sum(card_show)                       card_show,
-                sum(`share`)                         `share`,
-                sum(`comment`)                       `comment`,
-                sum(`like`)                          `like`,
-                sum(follow)                          follow,
-                sum(home_visited)                    home_visited,
-                sum(ies_challenge_click)             ies_challenge_click,
-                sum(ies_music_click)                 ies_music_click,
-                sum(location_click)                  location_click,
-                sum(message_action)                  message_action,
-                sum(click_landing_page)              click_landing_page,
-                sum(click_shopwindow)                click_shopwindow,
-                sum(click_website)                   click_website,
-                sum(click_download)                  click_download,
-                sum(click_call_dy)                   click_call_dy,
-                sum(cpc)                             cpc,
-                sum(cpm)                             cpm,
-                sum(cpa)                             cpa,
-                round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
-                round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
-                round(
-                        sum(round(play_duration_10s)) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_10s_rate,
-                round(
-                        sum(play_50_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_50_feed_break_rate,
-                round(
-                        sum(play_25_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_25_feed_break_rate,
-                round(
-                        sum(play_duration_5s_rate) / {day_count},
-                        3
-                    )                                play_duration_5s_rate,
-                round(
-                        sum(play_duration_2s) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_2s_rate,
-                round(
-                        sum(average_play_progress) / {day_count},
-                        3
-                    )                                average_play_progress,
-                round(
-                        sum(play_100_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_100_feed_break_rate,
-                round(
-                        sum(play_duration_3s) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_3s_rate,
-                round(
-                        sum(play_75_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_75_feed_break_rate,
-                sum(play_duration)                   play_duration,
-                sum(play_duration_3s)                play_duration_3s,
-                sum(play_duration_2s)                play_duration_2s,
-                sum(play_duration_10s)               play_duration_10s,
-                round(
-                        sum(average_video_play) / {day_count},
-                        3
-                    )                                average_video_play,
-                sum(avg_rank)                        avg_rank,
-                sum(submit_certification_count)      submit_certification_count,
-                sum(approval_count)                  approval_count,
-                sum(first_order_count)               first_rental_order_count,
-                sum(first_rental_order_count)        first_order_count,
-                sum(commute_first_pay_count)         commute_first_pay_count
+          sum(cost) cost,
+          sum(`show`) `show`,
+          ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+          sum(click) click,
+          ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+          ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+          sum(`convert`) `convert`,
+          ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+          ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+          sum(deep_convert) deep_convert,
+          ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
+          ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+          sum(attribution_convert) attribution_convert,
+          ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
+          sum(attribution_deep_convert) attribution_deep_convert,
+          ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
+          sum(download_start) download_start,
+          ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
+          ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
+          sum(download_finish) download_finish,
+          ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
+          ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+          sum(click_install) click_install,
+          sum(install_finish) install_finish,
+          ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
+          ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+          sum(active) active,
+          ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+          ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+          sum(register) register,
+          ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+          ifnull(round(sum(active_register_rate) /{day_count} * 100,3),0) active_register_rate,
+          sum(active_pay_amount) active_pay_amount,
+          sum(next_day_open) next_day_open,
+          ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
+          ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+          sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+          ifnull(round(sum(cost) / sum(	attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
+          ifnull(round(sum(	attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+          sum(game_addiction) game_addiction,
+          ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
+          ifnull(round(sum(game_addiction_rate) /{day_count} * 100,3),0) game_addiction_rate,
+          sum(pay_count) pay_count,
+          ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+          ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+          sum(loan_completion) loan_completion,
+          ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
+          ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+          ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+          ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
+          sum(loan_credit) loan_credit,
+          ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
+          ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+          sum(in_app_uv) in_app_uv,
+          sum(in_app_detail_uv) in_app_detail_uv,
+          sum(in_app_cart) in_app_cart,
+          sum(in_app_pay) in_app_pay,
+          sum(in_app_order) in_app_order,
+          ifnull(round(sum(	attribution_game_pay_7d_count) /{day_count}, 3),0) attribution_game_pay_7d_count,
+          ifnull(round(sum(	attribution_game_pay_7d_cost) /{day_count}, 3),0) attribution_game_pay_7d_cost,
+          ifnull(round(sum(	attribution_active_pay_7d_per_count) /{day_count}, 3),0) attribution_active_pay_7d_per_count,
+          sum(game_pay_cost) game_pay_cost,
+          sum(game_pay_count) game_pay_count,
+          sum(phone) phone,
+          sum(form) form,
+          sum(map_search) map_search,
+          sum(button) button,
+          sum(`view`) `view`,
+          sum(download) download,
+          sum(qq) qq,
+          sum(lottery) lottery,
+          sum(vote) vote,
+          sum(message) message,
+          sum(redirect) redirect,
+          sum(shopping) shopping,
+          sum(consult) consult,
+          sum(wechat) wechat,
+          sum(phone_confirm) phone_confirm,
+          sum(phone_connect) phone_connect,
+          sum(consult_effective) consult_effective,
+          sum(coupon) coupon,
+          sum(coupon_single_page) coupon_single_page,
+          sum(redirect_to_shop) redirect_to_shop,
+          sum(poi_collect) poi_collect,
+          sum(poi_address_click) poi_address_click,
+          sum(luban_order_cnt) luban_order_cnt,
+          sum(luban_order_stat_amount) luban_order_stat_amount,
+          sum(luban_order_roi) luban_order_roi,
+          sum(luban_live_enter_cnt) luban_live_enter_cnt,
+          sum(live_watch_one_minute_count) live_watch_one_minute_count,
+          sum(luban_live_follow_cnt) luban_live_follow_cnt,
+          sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+          sum(luban_live_comment_cnt) luban_live_comment_cnt,
+          sum(luban_live_share_cnt) luban_live_share_cnt,
+          sum(luban_live_gift_cnt) luban_live_gift_cnt,
+          sum(luban_live_gift_amount) luban_live_gift_amount,
+          sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+          sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+          sum(luban_live_pay_order_count) luban_live_pay_order_count,
+          sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+          sum(wechat_login_count) wechat_login_count,
+          sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
+          sum(wechat_first_pay_count) wechat_first_pay_count,
+          sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
+          ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+          ifnull(round(sum(	attribution_wechat_first_pay_30d_count) / sum(	attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+          sum(wechat_pay_amount) wechat_pay_amount,
+          sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+          sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+          sum(phone_effective) phone_effective,
+          sum(total_play) total_play,
+          sum(valid_play) valid_play,
+          ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
+          ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+          sum(play_25_feed_break) play_25_feed_break,
+          sum(play_50_feed_break) play_50_feed_break,
+          sum(play_75_feed_break) play_75_feed_break,
+          sum(play_100_feed_break) play_100_feed_break,
+          ifnull(round(sum(average_play_time_per_play) /{day_count}, 3),0) average_play_time_per_play,
+          ifnull(round(sum(play_over_rate) /{day_count} * 100,3),0) play_over_rate,
+          ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+          sum(wifi_play) wifi_play,
+          ifnull(round(sum(play_duration_sum) /{day_count}, 3),0) play_duration_sum,
+          sum(advanced_creative_phone_click) advanced_creative_phone_click,
+          sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+          sum(advanced_creative_form_click) advanced_creative_form_click,
+          sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+          sum(advanced_creative_form_submit) advanced_creative_form_submit,
+          sum(card_show) card_show,
+          sum(`share`) `share`,
+          sum(`comment`) `comment`,
+          sum(`like`) `like`,
+          sum(follow) follow,
+          sum(home_visited) home_visited,
+          sum(ies_challenge_click) ies_challenge_click,
+          sum(ies_music_click) ies_music_click,
+          sum(location_click) location_click,
+          sum(message_action) message_action,
+          sum(click_landing_page) click_landing_page,
+          sum(click_shopwindow) click_shopwindow,
+          sum(click_website) click_website,
+          sum(click_download) click_download,
+          sum(click_call_dy) click_call_dy,
+          sum(cpc) cpc,
+          sum(cpm) cpm,
+          sum(cpa) cpa,
+          ifnull(round(sum(interact_per_cost) /{day_count}, 3),0) interact_per_cost,
+          ifnull(round(sum(convert_show_rate) /{day_count}, 3),0) convert_show_rate,
+          ifnull(round(sum(play_duration_10s) / sum(total_play) * 100,3),0) play_duration_10s_rate,
+          ifnull(round(sum(play_50_feed_break) / sum(total_play) * 100,3),0) play_50_feed_break_rate,
+          ifnull(round(sum(play_25_feed_break) / sum(total_play) * 100,3),0) play_25_feed_break_rate,
+          ifnull(round(sum(play_duration_5s_rate) /{day_count}, 3),0) play_duration_5s_rate,
+          ifnull(round(sum(play_duration_2s) / sum(total_play) * 100,3),0) play_duration_2s_rate,
+          ifnull(round(sum(average_play_progress) /{day_count}, 3),0) average_play_progress,
+          ifnull(round(sum(play_100_feed_break) / sum(total_play) * 100,3),0) play_100_feed_break_rate,
+          ifnull(round(sum(play_duration_3s) / sum(total_play) * 100,3),0) play_duration_3s_rate,
+          ifnull(round(sum(play_75_feed_break) / sum(total_play) * 100,3),0) play_75_feed_break_rate,
+          sum(play_duration) play_duration,
+          sum(play_duration_3s) play_duration_3s,
+          sum(play_duration_2s) play_duration_2s,
+          sum(play_duration_10s) play_duration_10s,
+          ifnull(round(sum(average_video_play) /{day_count}, 3),0) average_video_play,
+          sum(avg_rank) avg_rank,
+          sum(submit_certification_count) submit_certification_count,
+          sum(approval_count) approval_count,
+          sum(first_order_count) first_rental_order_count,
+          sum(first_rental_order_count) first_order_count,
+          sum(commute_first_pay_count) commute_first_pay_count
          FROM media_api.bytedance_material_report_daily zhubiao
          WHERE image_mode IN (
     'CREATIVE_IMAGE_MODE_SMALL',
@@ -618,20 +421,14 @@ FROM (
     'CREATIVE_IMAGE_MODE_GIF',
     'TOUTIAO_SEARCH_AD_IMAGE',
     'SEARCH_AD_SMALL_IMAGE',
-    'CREATIVE_IMAGE_MODE_UNION_SPLASH'
-             )
-           AND stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL {day_count}  DAY),
-                 '%Y%m%d'
-             )
-         GROUP BY advertiser_id,
+    'CREATIVE_IMAGE_MODE_UNION_SPLASH')
+       AND stat_datetime >= date_format(date_sub({date_time}, INTERVAL ({day_count})  DAY),'%Y%m%d')
+       GROUP BY advertiser_id,
                   material_id,
                   image_mode,
-                  inventory
-     ) report
-        LEFT JOIN (select advertiser_id,signature,material_id,filename,image_url 
-        from  `media_api`.bytedance_file_image_get group by advertiser_id,signature,material_id,filename,image_url)  
-        video 
+                  inventory) report
+LEFT JOIN (select advertiser_id,signature,material_id,filename,image_url
+from  `media_api`.bytedance_file_image_get group by advertiser_id,signature,material_id,filename,image_url)  video 
 ON report.account_id = video.advertiser_id AND report.material_id = video.material_id
           LEFT JOIN `jeecg-boot`.ctop_user_allocation cua
                    ON report.account_id = cua.account_id

+ 166 - 349
Apietl/bytedance_etl/Q4Task/AppBytedanceProductReportBusi.py

@@ -24,362 +24,179 @@ class AppBytedanceProductReportBusi:
             sql = """
 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_product_report_busi_{day_count}d
-SELECT concat(
-               date_format(
-                       date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
-                       '%Y%m%d'
-                   ),
-               '-',
-               {date_time}
-           )                                time,
-       uc.company_id,
-       CASE
-           WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
+SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d'),'-',{date_time}) time,
+               uc.company_id,
+               CASE
+               WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
                '北京汇创思拓数字科技有限公司'
-           WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
+               WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
                '广州汇创思拓数字科技有限公司'
-           WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
+               WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
                '上海汇创思拓数字科技有限公司'
-           ELSE
+               ELSE
                uc.company_name
-           END                              company_name,
-       cn.id                                product_id,
-       cn.product_name,
-       count(report.advertiser_id)          account_count,
-       sum(cost)                            cost,
-       sum(`show`)                          `show`,
-       round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-       sum(click)                           click,
-       round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-       round(
-               sum(click) / sum(`show`) * 100,
-               3
-           )                                ctr,
-       sum(`convert`)                       `convert`,
-       round(sum(cost) / sum(`convert`), 3) convert_cost,
-       round(
-               sum(`convert`) / sum(click) * 100,
-               3
-           )                                convert_rate,
-       sum(deep_convert)                    deep_convert,
-       round(
-               sum(cost) / sum(deep_convert),
-               3
-           )                                deep_convert_cost,
-       round(
-               sum(deep_convert) / sum(`convert`) * 100,
-               3
-           )                                deep_convert_rate,
-       sum(attribution_convert)             attribution_convert,
-       round(
-               sum(cost) / sum(attribution_convert),
-               3
-           )                                attribution_convert_cost,
-       sum(attribution_deep_convert)        attribution_deep_convert,
-       round(
-               sum(cost) / sum(attribution_deep_convert),
-               3
-           )                                attribution_deep_convert_cost,
-       sum(download_start)                  download_start,
-       round(
-               sum(cost) / sum(download_start),
-               3
-           )                                download_start_cost,
-       round(
-               sum(download_start) / sum(click),
-               3
-           )                                download_start_rate,
-       sum(download_finish)                 download_finish,
-       round(
-               sum(cost) / sum(download_finish),
-               3
-           )                                download_finish_cost,
-       round(
-               sum(download_finish) / sum(download_start) * 100,
-               3
-           )                                download_finish_rate,
-       sum(click_install)                   click_install,
-       sum(install_finish)                  install_finish,
-       round(
-               sum(cost) / sum(install_finish),
-               3
-           )                                install_finish_cost,
-       round(
-               sum(install_finish) / sum(download_finish) * 100,
-               3
-           )                                install_finish_rate,
-       sum(active)                          active,
-       round(sum(cost) / sum(active), 3)    active_cost,
-       round(
-               sum(active) / sum(click) * 100,
-               3
-           )                                active_rate,
-       sum(register)                        register,
-       round(sum(cost) / sum(register), 3)  active_register_cost,
-       round(
-               sum(active_register_rate) / {day_count} * 100,
-               3
-           )                                active_register_rate,
-       sum(next_day_open)                   next_day_open,
-       round(
-               sum(cost) / sum(next_day_open),
-               3
-           )                                next_day_open_cost,
-       round(
-               sum(next_day_open) / sum(active) * 100,
-               3
-           )                                next_day_open_rate,
-       sum(
-               attribution_next_day_open_cnt
-           )                                attribution_next_day_open_cnt,
-       round(
-                   sum(cost) / sum(
-                       attribution_next_day_open_cnt
-                   ),
-                   3
-           )                                attribution_next_day_open_cost,
-       round(
-                       sum(
-                               attribution_next_day_open_cnt
-                           ) / sum(active) * 100,
-                       3
-           )                                attribution_next_day_open_rate,
-       sum(game_addiction)                  game_addiction,
-       round(
-               sum(cost) / sum(game_addiction),
-               3
-           )                                game_addiction_cost,
-       round(
-               sum(game_addiction_rate) / {day_count} * 100,
-               3
-           )                                game_addiction_rate,
-       sum(pay_count)                       pay_count,
-       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-       round(
-               sum(pay_count) / sum(active) * 100,
-               3
-           )                                active_pay_rate,
-       sum(loan_completion)                 loan_completion,
-       round(
-               sum(cost) / sum(loan_completion),
-               3
-           )                                loan_completion_cost,
-       round(
-               sum(loan_completion) / sum(register) * 100,
-               3
-           )                                loan_completion_rate,
-       round(sum(pre_loan_credit), 3)       pre_loan_credit,
-       round(
-               sum(cost) / sum(pre_loan_credit),
-               3
-           )                                pre_loan_credit_cost,
-       sum(loan_credit)                     loan_credit,
-       round(
-               sum(cost) / sum(loan_credit),
-               3
-           )                                loan_credit_cost,
-       round(
-               sum(loan_credit) / sum(loan_completion) * 100,
-               3
-           )                                loan_credit_rate,
-       sum(in_app_uv)                       in_app_uv,
-       sum(in_app_detail_uv)                in_app_detail_uv,
-       sum(in_app_cart)                     in_app_cart,
-       sum(in_app_pay)                      in_app_pay,
-       sum(in_app_order)                    in_app_order,
-       round(
-                   sum(
-                           attribution_game_pay_7d_count
-                       ) / {day_count},
-                   3
-           )                                attribution_game_pay_7d_count,
-       round(
-                   sum(
-                           attribution_game_pay_7d_cost
-                       ) / {day_count},
-                   3
-           )                                attribution_game_pay_7d_cost,
-       round(
-                   sum(
-                           attribution_active_pay_7d_per_count
-                       ) / {day_count},
-                   3
-           )                                attribution_active_pay_7d_per_count,
-       sum(game_pay_cost)                   game_pay_cost,
-       sum(game_pay_count)                  game_pay_count,
-       sum(phone)                           phone,
-       sum(form)                            form,
-       sum(map_search)                      map_search,
-       sum(button)                          button,
-       sum(`view`)                          `view`,
-       sum(download)                        download,
-       sum(qq)                              qq,
-       sum(lottery)                         lottery,
-       sum(vote)                            vote,
-       sum(message)                         message,
-       sum(redirect)                        redirect,
-       sum(shopping)                        shopping,
-       sum(consult)                         consult,
-       sum(wechat)                          wechat,
-       sum(phone_confirm)                   phone_confirm,
-       sum(phone_connect)                   phone_connect,
-       sum(consult_effective)               consult_effective,
-       sum(coupon)                          coupon,
-       sum(coupon_single_page)              coupon_single_page,
-       sum(redirect_to_shop)                redirect_to_shop,
-       sum(poi_collect)                     poi_collect,
-       sum(poi_address_click)               poi_address_click,
-       sum(luban_order_cnt)                 luban_order_cnt,
-       sum(luban_order_stat_amount)         luban_order_stat_amount,
-       sum(luban_order_roi)                 luban_order_roi,
-       sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-       sum(
-               live_watch_one_minute_count
-           )                                live_watch_one_minute_count,
-       sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-       sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-       sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-       sum(luban_live_share_cnt)            luban_live_share_cnt,
-       sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-       sum(luban_live_gift_amount)          luban_live_gift_amount,
-       sum(
-               luban_live_slidecart_click_cnt
-           )                                luban_live_slidecart_click_cnt,
-       sum(
-               luban_live_click_product_cnt
-           )                                luban_live_click_product_cnt,
-       sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-       sum(
-               luban_live_pay_order_stat_cost
-           )                                luban_live_pay_order_stat_cost,
-       sum(live_component_click_count)      live_component_click_count,
-       round(
-               sum(cost) / sum(live_component_click_count),
-               3
-           )                                live_component_click_cost,
-       round(
-               sum(live_component_click_count) / {day_count} * 100,
-               3
-           )                                live_component_click_rate,
-       sum(wechat_login_count)              wechat_login_count,
-       sum(
-               attribution_wechat_login_30d_count
-           )                                attribution_wechat_login_30d_count,
-       round(
-               sum(cost) / sum(wechat_login_count),
-               3
-           )                                wechat_login_cost,
-       round(
-                   sum(cost) / sum(
-                       attribution_wechat_login_30d_count
-                   ),
-                   3
-           )                                attribution_wechat_login_30d_cost,
-       sum(wechat_first_pay_count)          wechat_first_pay_count,
-       sum(
-               attribution_wechat_first_pay_30d_count
-           )                                attribution_wechat_first_pay_30d_count,
-       round(
-               sum(cost) / sum(wechat_first_pay_count),
-               3
-           )                                wechat_first_pay_cost,
-       round(
-                   sum(cost) / sum(
-                       attribution_wechat_first_pay_30d_count
-                   ),
-                   3
-           )                                attribution_wechat_first_pay_30d_cost,
-       round(
-               sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-               3
-           )                                wechat_first_pay_rate,
-       round(
-                       sum(
-                               attribution_wechat_first_pay_30d_count
-                           ) / sum(
-                               attribution_wechat_login_30d_count
-                           ) * 100,
-                       3
-           )                                attribution_wechat_first_pay_30d_rate,
-       sum(wechat_pay_amount)               wechat_pay_amount,
-       sum(
-               attribution_wechat_pay_30d_amount
-           )                                attribution_wechat_pay_30d_amount,
-       sum(
-               attribution_wechat_pay_30d_roi
-           )                                attribution_wechat_pay_30d_roi,
-       sum(phone_effective)                 phone_effective,
-       sum(total_play)                      total_play,
-       sum(valid_play)                      valid_play,
-       round(
-               sum(cost) / sum(valid_play),
-               3
-           )                                valid_play_cost,
-       round(
-               sum(valid_play) / sum(`show`) * 100,
-               3
-           )                                valid_play_rate,
-       sum(play_25_feed_break)              play_25_feed_break,
-       sum(play_50_feed_break)              play_50_feed_break,
-       sum(play_75_feed_break)              play_75_feed_break,
-       sum(play_100_feed_break)             play_100_feed_break,
-       round(
-               sum(average_play_time_per_play) / {day_count},
-               3
-           )                                average_play_time_per_play,
-       round(
-               sum(play_over_rate) / {day_count} * 100,
-               3
-           )                                play_over_rate,
-       round(
-               sum(wifi_play) / sum(total_play) * 100,
-               3
-           )                                wifi_play_rate,
-       sum(wifi_play)                       wifi_play,
-       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-       sum(
-               advanced_creative_phone_click
-           )                                advanced_creative_phone_click,
-       sum(
-               advanced_creative_counsel_click
-           )                                advanced_creative_counsel_click,
-       sum(
-               advanced_creative_form_click
-           )                                advanced_creative_form_click,
-       sum(
-               advanced_creative_coupon_addition
-           )                                advanced_creative_coupon_addition,
-       sum(
-               advanced_creative_form_submit
-           )                                advanced_creative_form_submit,
-       sum(card_show)                       card_show,
-       sum(`share`)                         `share`,
-       sum(`comment`)                       `comment`,
-       sum(`like`)                          `like`,
-       sum(follow)                          follow,
-       sum(home_visited)                    home_visited,
-       sum(ies_challenge_click)             ies_challenge_click,
-       sum(ies_music_click)                 ies_music_click,
-       sum(location_click)                  location_click,
-       sum(message_action)                  message_action,
-       sum(click_landing_page)              click_landing_page,
-       sum(click_shopwindow)                click_shopwindow,
-       sum(click_website)                   click_website,
-       sum(click_download)                  click_download,
-       sum(click_call_dy)                   click_call_dy,
-       sum(submit_certification_count)      submit_certification_count,
-       sum(approval_count)                  approval_count,
-       sum(first_order_count)               first_rental_order_count,
-       sum(first_rental_order_count)        first_order_count,
-       sum(commute_first_pay_count)         commute_first_pay_count
+               END                              company_name,
+               cn.id                                product_id,
+               cn.product_name,
+               count(report.advertiser_id)          account_count,
+               sum(cost) cost,
+               sum(`show`) `show`,
+               ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+               sum(click)click,
+               ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+               ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+               sum(`convert`)`convert`,
+               ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+               ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+               sum(deep_convert) deep_convert,
+               ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+               ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+               sum(attribution_convert)attribution_convert,
+               ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+               sum(attribution_deep_convert) attribution_deep_convert,
+               ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+               sum(download_start) download_start,
+               ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+               ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+               sum(download_finish) download_finish,
+               ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+               ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+               sum(click_install)click_install,
+               sum(install_finish) install_finish,
+               ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+               ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+               sum(active) active,
+               ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+               ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+               sum(register)register,
+               ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+               ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+               sum(next_day_open)next_day_open,
+               ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+               ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+               sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+               ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+               ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+               sum(game_addiction) game_addiction,
+               ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+               ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+               sum(pay_count)pay_count,
+               ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+               ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+               sum(loan_completion) loan_completion,
+               ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+               ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+               ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+               ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+               sum(loan_credit)loan_credit,
+               ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+               ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+               sum(in_app_uv)in_app_uv,
+               sum(in_app_detail_uv) in_app_detail_uv,
+               sum(in_app_cart) in_app_cart,
+               sum(in_app_pay) in_app_pay,
+               sum(in_app_order) in_app_order,
+               ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+               ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+               ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+               sum(game_pay_cost)game_pay_cost,
+               sum(game_pay_count) game_pay_count,
+               sum(phone) phone,
+               sum(form) form,
+               sum(map_search) map_search,
+               sum(button) button,
+               sum(`view`) `view`,
+               sum(download)download,
+               sum(qq)qq,
+               sum(lottery)lottery,
+               sum(vote) vote,
+               sum(message)message,
+               sum(redirect)redirect,
+               sum(shopping)shopping,
+               sum(consult)consult,
+               sum(wechat) wechat,
+               sum(phone_confirm)phone_confirm,
+               sum(phone_connect)phone_connect,
+               sum(consult_effective)consult_effective,
+               sum(coupon) coupon,
+               sum(coupon_single_page) coupon_single_page,
+               sum(redirect_to_shop) redirect_to_shop,
+               sum(poi_collect)poi_collect,
+               sum(poi_address_click)poi_address_click,
+               sum(luban_order_cnt) luban_order_cnt,
+               sum(luban_order_stat_amount)luban_order_stat_amount,
+               sum(luban_order_roi) luban_order_roi,
+               sum(luban_live_enter_cnt) luban_live_enter_cnt,
+               sum(live_watch_one_minute_count) live_watch_one_minute_count,
+               sum(luban_live_follow_cnt) luban_live_follow_cnt,
+               sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+               sum(luban_live_comment_cnt) luban_live_comment_cnt,
+               sum(luban_live_share_cnt) luban_live_share_cnt,
+               sum(luban_live_gift_cnt)luban_live_gift_cnt,
+               sum(luban_live_gift_amount) luban_live_gift_amount,
+               sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+               sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+               sum(luban_live_pay_order_count) luban_live_pay_order_count,
+               sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+               sum(live_component_click_count) live_component_click_count,
+               ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+               ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+               sum(wechat_login_count) wechat_login_count,
+               sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+               sum(wechat_first_pay_count) wechat_first_pay_count,
+               sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+               ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+               ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+               sum(wechat_pay_amount)wechat_pay_amount,
+               sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+               sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+               sum(phone_effective) phone_effective,
+               sum(total_play) total_play,
+               sum(valid_play) valid_play,
+               ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+               ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+               sum(play_25_feed_break) play_25_feed_break,
+               sum(play_50_feed_break) play_50_feed_break,
+               sum(play_75_feed_break) play_75_feed_break,
+               sum(play_100_feed_break)play_100_feed_break,
+               ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+               ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+               ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+               sum(wifi_play)wifi_play,
+               ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+               sum(advanced_creative_phone_click) advanced_creative_phone_click,
+               sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+               sum(advanced_creative_form_click) advanced_creative_form_click,
+               sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+               sum(advanced_creative_form_submit) advanced_creative_form_submit,
+               sum(card_show)card_show,
+               sum(`share`)`share`,
+               sum(`comment`)`comment`,
+               sum(`like`) `like`,
+               sum(follow) follow,
+               sum(home_visited) home_visited,
+               sum(ies_challenge_click)ies_challenge_click,
+               sum(ies_music_click) ies_music_click,
+               sum(location_click) location_click,
+               sum(message_action) message_action,
+               sum(click_landing_page) click_landing_page,
+               sum(click_shopwindow) click_shopwindow,
+               sum(click_website)click_website,
+               sum(click_download) click_download,
+               sum(click_call_dy)click_call_dy,
+               sum(submit_certification_count) submit_certification_count,
+               sum(approval_count) approval_count,
+               sum(first_order_count)first_rental_order_count,
+               sum(first_rental_order_count) first_order_count,
+               sum(commute_first_pay_count)commute_first_pay_count
 FROM (
          SELECT *
          FROM media_api.bytedance_advertiser_report_daily
-         WHERE stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
-                 '%Y%m%d'
-             )
-     ) report
+         WHERE stat_datetime >= date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d')) report
          LEFT JOIN `jeecg-boot`.ctop_user_allocation cua ON report.advertiser_id = cua.account_id
          LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
          LEFT JOIN `jeecg-boot`.ctop_product cn ON cp.product_id = cn.id

+ 167 - 343
Apietl/bytedance_etl/Q4Task/AppBytedanceProductReportBusiMonth.py

@@ -24,356 +24,180 @@ class AppBytedanceProductReportBusiMonth:
             sql = """
 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 REPLACE INTO application.app_bytedance_product_report_busi_m
-SELECT 
-        date_format({date_time},'%Y%m')         as          stat_mon,
-       uc.company_id,
-       CASE
-           WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
+               SELECT 
+               date_format({date_time},'%Y%m')  as  stat_mon,
+               uc.company_id,
+               CASE
+               WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN
                '北京汇创思拓数字科技有限公司'
-           WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
+               WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN
                '广州汇创思拓数字科技有限公司'
-           WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
+               WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN
                '上海汇创思拓数字科技有限公司'
-           ELSE
+               ELSE
                uc.company_name
-           END                              company_name,
-       cn.id                                product_id,
-       cn.product_name,
-       count(report.advertiser_id)          account_count,
-       sum(cost)                            cost,
-       sum(`show`)                          `show`,
-       round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-       sum(click)                           click,
-       round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-       round(
-               sum(click) / sum(`show`) * 100,
-               3
-           )                                ctr,
-       sum(`convert`)                       `convert`,
-       round(sum(cost) / sum(`convert`), 3) convert_cost,
-       round(
-               sum(`convert`) / sum(click) * 100,
-               3
-           )                                convert_rate,
-       sum(deep_convert)                    deep_convert,
-       round(
-               sum(cost) / sum(deep_convert),
-               3
-           )                                deep_convert_cost,
-       round(
-               sum(deep_convert) / sum(`convert`) * 100,
-               3
-           )                                deep_convert_rate,
-       sum(attribution_convert)             attribution_convert,
-       round(
-               sum(cost) / sum(attribution_convert),
-               3
-           )                                attribution_convert_cost,
-       sum(attribution_deep_convert)        attribution_deep_convert,
-       round(
-               sum(cost) / sum(attribution_deep_convert),
-               3
-           )                                attribution_deep_convert_cost,
-       sum(download_start)                  download_start,
-       round(
-               sum(cost) / sum(download_start),
-               3
-           )                                download_start_cost,
-       round(
-               sum(download_start) / sum(click),
-               3
-           )                                download_start_rate,
-       sum(download_finish)                 download_finish,
-       round(
-               sum(cost) / sum(download_finish),
-               3
-           )                                download_finish_cost,
-       round(
-               sum(download_finish) / sum(download_start) * 100,
-               3
-           )                                download_finish_rate,
-       sum(click_install)                   click_install,
-       sum(install_finish)                  install_finish,
-       round(
-               sum(cost) / sum(install_finish),
-               3
-           )                                install_finish_cost,
-       round(
-               sum(install_finish) / sum(download_finish) * 100,
-               3
-           )                                install_finish_rate,
-       sum(active)                          active,
-       round(sum(cost) / sum(active), 3)    active_cost,
-       round(
-               sum(active) / sum(click) * 100,
-               3
-           )                                active_rate,
-       sum(register)                        register,
-       round(sum(cost) / sum(register), 3)  active_register_cost,
-       round(
-               sum(active_register_rate) / {day_count} * 100,
-               3
-           )                                active_register_rate,
-       sum(next_day_open)                   next_day_open,
-       round(
-               sum(cost) / sum(next_day_open),
-               3
-           )                                next_day_open_cost,
-       round(
-               sum(next_day_open) / sum(active) * 100,
-               3
-           )                                next_day_open_rate,
-       sum(
-               attribution_next_day_open_cnt
-           )                                attribution_next_day_open_cnt,
-       round(
-                   sum(cost) / sum(
-                       attribution_next_day_open_cnt
-                   ),
-                   3
-           )                                attribution_next_day_open_cost,
-       round(
-                       sum(
-                               attribution_next_day_open_cnt
-                           ) / sum(active) * 100,
-                       3
-           )                                attribution_next_day_open_rate,
-       sum(game_addiction)                  game_addiction,
-       round(
-               sum(cost) / sum(game_addiction),
-               3
-           )                                game_addiction_cost,
-       round(
-               sum(game_addiction_rate) / {day_count} * 100,
-               3
-           )                                game_addiction_rate,
-       sum(pay_count)                       pay_count,
-       round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-       round(
-               sum(pay_count) / sum(active) * 100,
-               3
-           )                                active_pay_rate,
-       sum(loan_completion)                 loan_completion,
-       round(
-               sum(cost) / sum(loan_completion),
-               3
-           )                                loan_completion_cost,
-       round(
-               sum(loan_completion) / sum(register) * 100,
-               3
-           )                                loan_completion_rate,
-       round(sum(pre_loan_credit), 3)       pre_loan_credit,
-       round(
-               sum(cost) / sum(pre_loan_credit),
-               3
-           )                                pre_loan_credit_cost,
-       sum(loan_credit)                     loan_credit,
-       round(
-               sum(cost) / sum(loan_credit),
-               3
-           )                                loan_credit_cost,
-       round(
-               sum(loan_credit) / sum(loan_completion) * 100,
-               3
-           )                                loan_credit_rate,
-       sum(in_app_uv)                       in_app_uv,
-       sum(in_app_detail_uv)                in_app_detail_uv,
-       sum(in_app_cart)                     in_app_cart,
-       sum(in_app_pay)                      in_app_pay,
-       sum(in_app_order)                    in_app_order,
-       round(
-                   sum(
-                           attribution_game_pay_7d_count
-                       ) / {day_count},
-                   3
-           )                                attribution_game_pay_7d_count,
-       round(
-                   sum(
-                           attribution_game_pay_7d_cost
-                       ) / {day_count},
-                   3
-           )                                attribution_game_pay_7d_cost,
-       round(
-                   sum(
-                           attribution_active_pay_7d_per_count
-                       ) / {day_count},
-                   3
-           )                                attribution_active_pay_7d_per_count,
-       sum(game_pay_cost)                   game_pay_cost,
-       sum(game_pay_count)                  game_pay_count,
-       sum(phone)                           phone,
-       sum(form)                            form,
-       sum(map_search)                      map_search,
-       sum(button)                          button,
-       sum(`view`)                          `view`,
-       sum(download)                        download,
-       sum(qq)                              qq,
-       sum(lottery)                         lottery,
-       sum(vote)                            vote,
-       sum(message)                         message,
-       sum(redirect)                        redirect,
-       sum(shopping)                        shopping,
-       sum(consult)                         consult,
-       sum(wechat)                          wechat,
-       sum(phone_confirm)                   phone_confirm,
-       sum(phone_connect)                   phone_connect,
-       sum(consult_effective)               consult_effective,
-       sum(coupon)                          coupon,
-       sum(coupon_single_page)              coupon_single_page,
-       sum(redirect_to_shop)                redirect_to_shop,
-       sum(poi_collect)                     poi_collect,
-       sum(poi_address_click)               poi_address_click,
-       sum(luban_order_cnt)                 luban_order_cnt,
-       sum(luban_order_stat_amount)         luban_order_stat_amount,
-       sum(luban_order_roi)                 luban_order_roi,
-       sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-       sum(
-               live_watch_one_minute_count
-           )                                live_watch_one_minute_count,
-       sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-       sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-       sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-       sum(luban_live_share_cnt)            luban_live_share_cnt,
-       sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-       sum(luban_live_gift_amount)          luban_live_gift_amount,
-       sum(
-               luban_live_slidecart_click_cnt
-           )                                luban_live_slidecart_click_cnt,
-       sum(
-               luban_live_click_product_cnt
-           )                                luban_live_click_product_cnt,
-       sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-       sum(
-               luban_live_pay_order_stat_cost
-           )                                luban_live_pay_order_stat_cost,
-       sum(live_component_click_count)      live_component_click_count,
-       round(
-               sum(cost) / sum(live_component_click_count),
-               3
-           )                                live_component_click_cost,
-       round(
-               sum(live_component_click_count) / {day_count} * 100,
-               3
-           )                                live_component_click_rate,
-       sum(wechat_login_count)              wechat_login_count,
-       sum(
-               attribution_wechat_login_30d_count
-           )                                attribution_wechat_login_30d_count,
-       round(
-               sum(cost) / sum(wechat_login_count),
-               3
-           )                                wechat_login_cost,
-       round(
-                   sum(cost) / sum(
-                       attribution_wechat_login_30d_count
-                   ),
-                   3
-           )                                attribution_wechat_login_30d_cost,
-       sum(wechat_first_pay_count)          wechat_first_pay_count,
-       sum(
-               attribution_wechat_first_pay_30d_count
-           )                                attribution_wechat_first_pay_30d_count,
-       round(
-               sum(cost) / sum(wechat_first_pay_count),
-               3
-           )                                wechat_first_pay_cost,
-       round(
-                   sum(cost) / sum(
-                       attribution_wechat_first_pay_30d_count
-                   ),
-                   3
-           )                                attribution_wechat_first_pay_30d_cost,
-       round(
-               sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-               3
-           )                                wechat_first_pay_rate,
-       round(
-                       sum(
-                               attribution_wechat_first_pay_30d_count
-                           ) / sum(
-                               attribution_wechat_login_30d_count
-                           ) * 100,
-                       3
-           )                                attribution_wechat_first_pay_30d_rate,
-       sum(wechat_pay_amount)               wechat_pay_amount,
-       sum(
-               attribution_wechat_pay_30d_amount
-           )                                attribution_wechat_pay_30d_amount,
-       sum(
-               attribution_wechat_pay_30d_roi
-           )                                attribution_wechat_pay_30d_roi,
-       sum(phone_effective)                 phone_effective,
-       sum(total_play)                      total_play,
-       sum(valid_play)                      valid_play,
-       round(
-               sum(cost) / sum(valid_play),
-               3
-           )                                valid_play_cost,
-       round(
-               sum(valid_play) / sum(`show`) * 100,
-               3
-           )                                valid_play_rate,
-       sum(play_25_feed_break)              play_25_feed_break,
-       sum(play_50_feed_break)              play_50_feed_break,
-       sum(play_75_feed_break)              play_75_feed_break,
-       sum(play_100_feed_break)             play_100_feed_break,
-       round(
-               sum(average_play_time_per_play) / {day_count},
-               3
-           )                                average_play_time_per_play,
-       round(
-               sum(play_over_rate) / {day_count} * 100,
-               3
-           )                                play_over_rate,
-       round(
-               sum(wifi_play) / sum(total_play) * 100,
-               3
-           )                                wifi_play_rate,
-       sum(wifi_play)                       wifi_play,
-       round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-       sum(
-               advanced_creative_phone_click
-           )                                advanced_creative_phone_click,
-       sum(
-               advanced_creative_counsel_click
-           )                                advanced_creative_counsel_click,
-       sum(
-               advanced_creative_form_click
-           )                                advanced_creative_form_click,
-       sum(
-               advanced_creative_coupon_addition
-           )                                advanced_creative_coupon_addition,
-       sum(
-               advanced_creative_form_submit
-           )                                advanced_creative_form_submit,
-       sum(card_show)                       card_show,
-       sum(`share`)                         `share`,
-       sum(`comment`)                       `comment`,
-       sum(`like`)                          `like`,
-       sum(follow)                          follow,
-       sum(home_visited)                    home_visited,
-       sum(ies_challenge_click)             ies_challenge_click,
-       sum(ies_music_click)                 ies_music_click,
-       sum(location_click)                  location_click,
-       sum(message_action)                  message_action,
-       sum(click_landing_page)              click_landing_page,
-       sum(click_shopwindow)                click_shopwindow,
-       sum(click_website)                   click_website,
-       sum(click_download)                  click_download,
-       sum(click_call_dy)                   click_call_dy,
-       sum(submit_certification_count)      submit_certification_count,
-       sum(approval_count)                  approval_count,
-       sum(first_order_count)               first_rental_order_count,
-       sum(first_rental_order_count)        first_order_count,
-       sum(commute_first_pay_count)         commute_first_pay_count
+               END   company_name,
+               cn.id   product_id,
+               cn.product_name,
+               count(report.advertiser_id)  account_count,
+               sum(cost) cost,
+               sum(`show`) `show`,
+               ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+               sum(click)click,
+               ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+               ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+               sum(`convert`)`convert`,
+               ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+               ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+               sum(deep_convert) deep_convert,
+               ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+               ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+               sum(attribution_convert)attribution_convert,
+               ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+               sum(attribution_deep_convert) attribution_deep_convert,
+               ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+               sum(download_start) download_start,
+               ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+               ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+               sum(download_finish) download_finish,
+               ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+               ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+               sum(click_install)click_install,
+               sum(install_finish) install_finish,
+               ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+               ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+               sum(active) active,
+               ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+               ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+               sum(register)register,
+               ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+               ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+               sum(next_day_open)next_day_open,
+               ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+               ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+               sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+               ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+               ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+               sum(game_addiction) game_addiction,
+               ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+               ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+               sum(pay_count)pay_count,
+               ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+               ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+               sum(loan_completion) loan_completion,
+               ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+               ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+               ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+               ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+               sum(loan_credit)loan_credit,
+               ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+               ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+               sum(in_app_uv)in_app_uv,
+               sum(in_app_detail_uv) in_app_detail_uv,
+               sum(in_app_cart) in_app_cart,
+               sum(in_app_pay) in_app_pay,
+               sum(in_app_order) in_app_order,
+               ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+               ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+               ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+               sum(game_pay_cost)game_pay_cost,
+               sum(game_pay_count) game_pay_count,
+               sum(phone) phone,
+               sum(form) form,
+               sum(map_search) map_search,
+               sum(button) button,
+               sum(`view`) `view`,
+               sum(download)download,
+               sum(qq)qq,
+               sum(lottery)lottery,
+               sum(vote) vote,
+               sum(message)message,
+               sum(redirect)redirect,
+               sum(shopping)shopping,
+               sum(consult)consult,
+               sum(wechat) wechat,
+               sum(phone_confirm)phone_confirm,
+               sum(phone_connect)phone_connect,
+               sum(consult_effective)consult_effective,
+               sum(coupon) coupon,
+               sum(coupon_single_page) coupon_single_page,
+               sum(redirect_to_shop) redirect_to_shop,
+               sum(poi_collect)poi_collect,
+               sum(poi_address_click)poi_address_click,
+               sum(luban_order_cnt) luban_order_cnt,
+               sum(luban_order_stat_amount)luban_order_stat_amount,
+               sum(luban_order_roi) luban_order_roi,
+               sum(luban_live_enter_cnt) luban_live_enter_cnt,
+               sum(live_watch_one_minute_count) live_watch_one_minute_count,
+               sum(luban_live_follow_cnt) luban_live_follow_cnt,
+               sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+               sum(luban_live_comment_cnt) luban_live_comment_cnt,
+               sum(luban_live_share_cnt) luban_live_share_cnt,
+               sum(luban_live_gift_cnt)luban_live_gift_cnt,
+               sum(luban_live_gift_amount) luban_live_gift_amount,
+               sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+               sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+               sum(luban_live_pay_order_count) luban_live_pay_order_count,
+               sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+               sum(live_component_click_count) live_component_click_count,
+               ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+               ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+               sum(wechat_login_count) wechat_login_count,
+               sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+               sum(wechat_first_pay_count) wechat_first_pay_count,
+               sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+               ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+               ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+               sum(wechat_pay_amount)wechat_pay_amount,
+               sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+               sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+               sum(phone_effective) phone_effective,
+               sum(total_play) total_play,
+               sum(valid_play) valid_play,
+               ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+               ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+               sum(play_25_feed_break) play_25_feed_break,
+               sum(play_50_feed_break) play_50_feed_break,
+               sum(play_75_feed_break) play_75_feed_break,
+               sum(play_100_feed_break)play_100_feed_break,
+               ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+               ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+               ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+               sum(wifi_play)wifi_play,
+               ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+               sum(advanced_creative_phone_click) advanced_creative_phone_click,
+               sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+               sum(advanced_creative_form_click) advanced_creative_form_click,
+               sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+               sum(advanced_creative_form_submit) advanced_creative_form_submit,
+               sum(card_show)card_show,
+               sum(`share`)`share`,
+               sum(`comment`)`comment`,
+               sum(`like`) `like`,
+               sum(follow) follow,
+               sum(home_visited) home_visited,
+               sum(ies_challenge_click)ies_challenge_click,
+               sum(ies_music_click) ies_music_click,
+               sum(location_click) location_click,
+               sum(message_action) message_action,
+               sum(click_landing_page) click_landing_page,
+               sum(click_shopwindow) click_shopwindow,
+               sum(click_website)click_website,
+               sum(click_download) click_download,
+               sum(click_call_dy)click_call_dy,
+               sum(submit_certification_count) submit_certification_count,
+               sum(approval_count) approval_count,
+               sum(first_order_count)first_rental_order_count,
+               sum(first_rental_order_count) first_order_count,
+               sum(commute_first_pay_count)commute_first_pay_count
 FROM (
          SELECT *
          FROM media_api.bytedance_advertiser_report_daily
-         WHERE stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL {day_count} DAY),
-                 '%Y%m%d'
-             )
-     ) report
+         WHERE stat_datetime >= date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d')) report
          LEFT JOIN `jeecg-boot`.ctop_user_allocation cua ON report.advertiser_id = cua.account_id
          LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
          LEFT JOIN `jeecg-boot`.ctop_product cn ON cp.product_id = cn.id

+ 153 - 325
Apietl/bytedance_etl/Q4Task/AppBytedanceProjectReportBusi.py

@@ -43,331 +43,159 @@ END company_name,
  cp.project_name,
  count(report.advertiser_id) account_num,
  sum(cost) cost,
- sum(`show`) `show`,
- round(sum(cost) / sum(`show`), 3) avg_show_cost,
- sum(click) click,
- round(sum(cost) / sum(`click`), 3) avg_click_cost,
- round(
-sum(click) / sum(`show`) * 100,
-3
-) ctr,
- sum(`convert`) `convert`,
- round(sum(cost) / sum(`convert`), 3) convert_cost,
- round(
-sum(`convert`) / sum(click) * 100,
-3
-) convert_rate,
- sum(deep_convert) deep_convert,
- round(
-sum(cost) / sum(deep_convert),
-3
-) deep_convert_cost,
- round(
-sum(deep_convert) / sum(`convert`) * 100,
-3
-) deep_convert_rate,
- sum(attribution_convert) attribution_convert,
- round(
-sum(cost) / sum(attribution_convert),
-3
-) attribution_convert_cost,
- sum(attribution_deep_convert) attribution_deep_convert,
- round(
-sum(cost) / sum(attribution_deep_convert),
-3
-) attribution_deep_convert_cost,
- sum(download_start) download_start,
- round(
-sum(cost) / sum(download_start),
-3
-) download_start_cost,
- round(
-sum(download_start) / sum(click),
-3
-) download_start_rate,
- sum(download_finish) download_finish,
- round(
-sum(cost) / sum(download_finish),
-3
-) download_finish_cost,
- round(
-sum(download_finish) / sum(download_start) * 100,
-3
-) download_finish_rate,
- sum(click_install) click_install,
- sum(install_finish) install_finish,
- round(
-sum(cost) / sum(install_finish),
-3
-) install_finish_cost,
- round(
-sum(install_finish) / sum(download_finish) * 100,
-3
-) install_finish_rate,
- sum(active) active,
- round(sum(cost) / sum(active), 3) active_cost,
- round(
-sum(active) / sum(click) * 100,
-3
-) active_rate,
- sum(register) register,
- round(sum(cost) / sum(register), 3) active_register_cost,
- round(
-sum(active_register_rate) / {day_count} * 100,
-3
-) active_register_rate,
- sum(next_day_open) next_day_open,
- round(
-sum(cost) / sum(next_day_open),
-3
-) next_day_open_cost,
- round(
-sum(next_day_open) / sum(active) * 100,
-3
-) next_day_open_rate,
- sum(
-attribution_next_day_open_cnt
-) attribution_next_day_open_cnt,
- round(
-sum(cost) / sum(
-attribution_next_day_open_cnt
-),
-3
-) attribution_next_day_open_cost,
- round(
-sum(
-attribution_next_day_open_cnt
-) / sum(active) * 100,
-3
-) attribution_next_day_open_rate,
- sum(game_addiction) game_addiction,
- round(
-sum(cost) / sum(game_addiction),
-3
-) game_addiction_cost,
- round(
-sum(game_addiction_rate) / {day_count} * 100,
-3
-) game_addiction_rate,
- sum(pay_count) pay_count,
- round(sum(cost) / sum(pay_count), 3) active_pay_cost,
- round(
-sum(pay_count) / sum(active) * 100,
-3
-) active_pay_rate,
- sum(loan_completion) loan_completion,
- round(
-sum(cost) / sum(loan_completion),
-3
-) loan_completion_cost,
- round(
-sum(loan_completion) / sum(register) * 100,
-3
-) loan_completion_rate,
- round(sum(pre_loan_credit), 3) pre_loan_credit,
- round(
-sum(cost) / sum(pre_loan_credit),
-3
-) pre_loan_credit_cost,
- sum(loan_credit) loan_credit,
- round(
-sum(cost) / sum(loan_credit),
-3
-) loan_credit_cost,
- round(
-sum(loan_credit) / sum(loan_completion) * 100,
-3
-) loan_credit_rate,
- sum(in_app_uv) in_app_uv,
- sum(in_app_detail_uv) in_app_detail_uv,
- sum(in_app_cart) in_app_cart,
- sum(in_app_pay) in_app_pay,
- sum(in_app_order) in_app_order,
- round(
-sum(
-attribution_game_pay_7d_count
-) / {day_count},
-3
-) attribution_game_pay_7d_count,
- round(
-sum(
-attribution_game_pay_7d_cost
-) / {day_count},
-3
-) attribution_game_pay_7d_cost,
- round(
-sum(
-attribution_active_pay_7d_per_count
-) / {day_count},
-3
-) attribution_active_pay_7d_per_count,
- sum(game_pay_cost) game_pay_cost,
- sum(game_pay_count) game_pay_count,
- sum(phone) phone,
- sum(form) form,
- sum(map_search) map_search,
- sum(button) button,
- sum(`view`) `view`,
- sum(download) download,
- sum(qq) qq,
- sum(lottery) lottery,
- sum(vote) vote,
- sum(message) message,
- sum(redirect) redirect,
- sum(shopping) shopping,
- sum(consult) consult,
- sum(wechat) wechat,
- sum(phone_confirm) phone_confirm,
- sum(phone_connect) phone_connect,
- sum(consult_effective) consult_effective,
- sum(coupon) coupon,
- sum(coupon_single_page) coupon_single_page,
- sum(redirect_to_shop) redirect_to_shop,
- sum(poi_collect) poi_collect,
- sum(poi_address_click) poi_address_click,
- sum(luban_order_cnt) luban_order_cnt,
- sum(luban_order_stat_amount) luban_order_stat_amount,
- sum(luban_order_roi) luban_order_roi,
- sum(luban_live_enter_cnt) luban_live_enter_cnt,
- sum(
-live_watch_one_minute_count
-) live_watch_one_minute_count,
- sum(luban_live_follow_cnt) luban_live_follow_cnt,
- sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
- sum(luban_live_comment_cnt) luban_live_comment_cnt,
- sum(luban_live_share_cnt) luban_live_share_cnt,
- sum(luban_live_gift_cnt) luban_live_gift_cnt,
- sum(luban_live_gift_amount) luban_live_gift_amount,
- sum(
-luban_live_slidecart_click_cnt
-) luban_live_slidecart_click_cnt,
- sum(
-luban_live_click_product_cnt
-) luban_live_click_product_cnt,
- sum(luban_live_pay_order_count) luban_live_pay_order_count,
- sum(
-luban_live_pay_order_stat_cost
-) luban_live_pay_order_stat_cost,
- sum(live_component_click_count) live_component_click_count,
- round(
-sum(cost) / sum(live_component_click_count),
-3
-) live_component_click_cost,
- round(
-sum(live_component_click_count) / {day_count} * 100,
-3
-) live_component_click_rate,
- sum(wechat_login_count) wechat_login_count,
- sum(
-attribution_wechat_login_30d_count
-) attribution_wechat_login_30d_count,
- round(
-sum(cost) / sum(wechat_login_count),
-3
-) wechat_login_cost,
- round(
-sum(cost) / sum(
-attribution_wechat_login_30d_count
-),
-3
-) attribution_wechat_login_30d_cost,
- sum(wechat_first_pay_count) wechat_first_pay_count,
- sum(
-attribution_wechat_first_pay_30d_count
-) attribution_wechat_first_pay_30d_count,
- round(
-sum(cost) / sum(wechat_first_pay_count),
-3
-) wechat_first_pay_cost,
- round(
-sum(cost) / sum(
-attribution_wechat_first_pay_30d_count
-),
-3
-) attribution_wechat_first_pay_30d_cost,
- round(
-sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-3
-) wechat_first_pay_rate,
- round(
-sum(
-attribution_wechat_first_pay_30d_count
-) / sum(
-attribution_wechat_login_30d_count
-) * 100,
-3
-) attribution_wechat_first_pay_30d_rate,
- sum(wechat_pay_amount) wechat_pay_amount,
- sum(
-attribution_wechat_pay_30d_amount
-) attribution_wechat_pay_30d_amount,
- sum(
-attribution_wechat_pay_30d_roi
-) attribution_wechat_pay_30d_roi,
- sum(phone_effective) phone_effective,
- sum(total_play) total_play,
- sum(valid_play) valid_play,
- round(
-sum(cost) / sum(valid_play),
-3
-) valid_play_cost,
- round(
-sum(valid_play) / sum(`show`) * 100,
-3
-) valid_play_rate,
- sum(play_25_feed_break) play_25_feed_break,
- sum(play_50_feed_break) play_50_feed_break,
- sum(play_75_feed_break) play_75_feed_break,
- sum(play_100_feed_break) play_100_feed_break,
- round(
-sum(average_play_time_per_play) / {day_count},
-3
-) average_play_time_per_play,
- round(
-sum(play_over_rate) / {day_count} * 100,
-3
-) play_over_rate,
- round(
-sum(wifi_play) / sum(total_play) * 100,
-3
-) wifi_play_rate,
- sum(wifi_play) wifi_play,
- round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
- sum(
-advanced_creative_phone_click
-) advanced_creative_phone_click,
- sum(
-advanced_creative_counsel_click
-) advanced_creative_counsel_click,
- sum(
-advanced_creative_form_click
-) advanced_creative_form_click,
- sum(
-advanced_creative_coupon_addition
-) advanced_creative_coupon_addition,
- sum(
-advanced_creative_form_submit
-) advanced_creative_form_submit,
- sum(card_show) card_show,
- sum(`share`) `share`,
- sum(`comment`) `comment`,
- sum(`like`) `like`,
- sum(follow) follow,
- sum(home_visited) home_visited,
- sum(ies_challenge_click) ies_challenge_click,
- sum(ies_music_click) ies_music_click,
- sum(location_click) location_click,
- sum(message_action) message_action,
- sum(click_landing_page) click_landing_page,
- sum(click_shopwindow) click_shopwindow,
- sum(click_website) click_website,
- sum(click_download) click_download,
- sum(click_call_dy) click_call_dy,
- sum(submit_certification_count) submit_certification_count,
- sum(approval_count) approval_count,
- sum(first_order_count) first_rental_order_count,
- sum(first_rental_order_count) first_order_count,
- sum(commute_first_pay_count) commute_first_pay_count
+               sum(`show`) `show`,
+               ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+               sum(click)click,
+               ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+               ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+               sum(`convert`)`convert`,
+               ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+               ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+               sum(deep_convert) deep_convert,
+               ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+               ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+               sum(attribution_convert)attribution_convert,
+               ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+               sum(attribution_deep_convert) attribution_deep_convert,
+               ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+               sum(download_start) download_start,
+               ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+               ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+               sum(download_finish) download_finish,
+               ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+               ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+               sum(click_install)click_install,
+               sum(install_finish) install_finish,
+               ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+               ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+               sum(active) active,
+               ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+               ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+               sum(register)register,
+               ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+               ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+               sum(next_day_open)next_day_open,
+               ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+               ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+               sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+               ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+               ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+               sum(game_addiction) game_addiction,
+               ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+               ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+               sum(pay_count)pay_count,
+               ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+               ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+               sum(loan_completion) loan_completion,
+               ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+               ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+               ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+               ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+               sum(loan_credit)loan_credit,
+               ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+               ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+               sum(in_app_uv)in_app_uv,
+               sum(in_app_detail_uv) in_app_detail_uv,
+               sum(in_app_cart) in_app_cart,
+               sum(in_app_pay) in_app_pay,
+               sum(in_app_order) in_app_order,
+               ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+               ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+               ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+               sum(game_pay_cost)game_pay_cost,
+               sum(game_pay_count) game_pay_count,
+               sum(phone) phone,
+               sum(form) form,
+               sum(map_search) map_search,
+               sum(button) button,
+               sum(`view`) `view`,
+               sum(download)download,
+               sum(qq)qq,
+               sum(lottery)lottery,
+               sum(vote) vote,
+               sum(message)message,
+               sum(redirect)redirect,
+               sum(shopping)shopping,
+               sum(consult)consult,
+               sum(wechat) wechat,
+               sum(phone_confirm)phone_confirm,
+               sum(phone_connect)phone_connect,
+               sum(consult_effective)consult_effective,
+               sum(coupon) coupon,
+               sum(coupon_single_page) coupon_single_page,
+               sum(redirect_to_shop) redirect_to_shop,
+               sum(poi_collect)poi_collect,
+               sum(poi_address_click)poi_address_click,
+               sum(luban_order_cnt) luban_order_cnt,
+               sum(luban_order_stat_amount)luban_order_stat_amount,
+               sum(luban_order_roi) luban_order_roi,
+               sum(luban_live_enter_cnt) luban_live_enter_cnt,
+               sum(live_watch_one_minute_count) live_watch_one_minute_count,
+               sum(luban_live_follow_cnt) luban_live_follow_cnt,
+               sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+               sum(luban_live_comment_cnt) luban_live_comment_cnt,
+               sum(luban_live_share_cnt) luban_live_share_cnt,
+               sum(luban_live_gift_cnt)luban_live_gift_cnt,
+               sum(luban_live_gift_amount) luban_live_gift_amount,
+               sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+               sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+               sum(luban_live_pay_order_count) luban_live_pay_order_count,
+               sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+               sum(live_component_click_count) live_component_click_count,
+               ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+               ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+               sum(wechat_login_count) wechat_login_count,
+               sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+               sum(wechat_first_pay_count) wechat_first_pay_count,
+               sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+               ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+               ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+               sum(wechat_pay_amount)wechat_pay_amount,
+               sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+               sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+               sum(phone_effective) phone_effective,
+               sum(total_play) total_play,
+               sum(valid_play) valid_play,
+               ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+               ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+               sum(play_25_feed_break) play_25_feed_break,
+               sum(play_50_feed_break) play_50_feed_break,
+               sum(play_75_feed_break) play_75_feed_break,
+               sum(play_100_feed_break)play_100_feed_break,
+               ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+               ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+               ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+               sum(wifi_play)wifi_play,
+               ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+               sum(advanced_creative_phone_click) advanced_creative_phone_click,
+               sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+               sum(advanced_creative_form_click) advanced_creative_form_click,
+               sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+               sum(advanced_creative_form_submit) advanced_creative_form_submit,
+               sum(card_show)card_show,
+               sum(`share`)`share`,
+               sum(`comment`)`comment`,
+               sum(`like`) `like`,
+               sum(follow) follow,
+               sum(home_visited) home_visited,
+               sum(ies_challenge_click)ies_challenge_click,
+               sum(ies_music_click) ies_music_click,
+               sum(location_click) location_click,
+               sum(message_action) message_action,
+               sum(click_landing_page) click_landing_page,
+               sum(click_shopwindow) click_shopwindow,
+               sum(click_website)click_website,
+               sum(click_download) click_download,
+               sum(click_call_dy)click_call_dy,
+               sum(submit_certification_count) submit_certification_count,
+               sum(approval_count) approval_count,
+               sum(first_order_count)first_rental_order_count,
+               sum(first_rental_order_count) first_order_count,
+               sum(commute_first_pay_count)commute_first_pay_count
 FROM
 (
 SELECT

+ 153 - 325
Apietl/bytedance_etl/Q4Task/AppBytedanceProjectReportBusiMonth.py

@@ -43,331 +43,159 @@ END company_name,
  cp.project_name,
  count(report.advertiser_id) account_num,
  sum(cost) cost,
- sum(`show`) `show`,
- round(sum(cost) / sum(`show`), 3) avg_show_cost,
- sum(click) click,
- round(sum(cost) / sum(`click`), 3) avg_click_cost,
- round(
-sum(click) / sum(`show`) * 100,
-3
-) ctr,
- sum(`convert`) `convert`,
- round(sum(cost) / sum(`convert`), 3) convert_cost,
- round(
-sum(`convert`) / sum(click) * 100,
-3
-) convert_rate,
- sum(deep_convert) deep_convert,
- round(
-sum(cost) / sum(deep_convert),
-3
-) deep_convert_cost,
- round(
-sum(deep_convert) / sum(`convert`) * 100,
-3
-) deep_convert_rate,
- sum(attribution_convert) attribution_convert,
- round(
-sum(cost) / sum(attribution_convert),
-3
-) attribution_convert_cost,
- sum(attribution_deep_convert) attribution_deep_convert,
- round(
-sum(cost) / sum(attribution_deep_convert),
-3
-) attribution_deep_convert_cost,
- sum(download_start) download_start,
- round(
-sum(cost) / sum(download_start),
-3
-) download_start_cost,
- round(
-sum(download_start) / sum(click),
-3
-) download_start_rate,
- sum(download_finish) download_finish,
- round(
-sum(cost) / sum(download_finish),
-3
-) download_finish_cost,
- round(
-sum(download_finish) / sum(download_start) * 100,
-3
-) download_finish_rate,
- sum(click_install) click_install,
- sum(install_finish) install_finish,
- round(
-sum(cost) / sum(install_finish),
-3
-) install_finish_cost,
- round(
-sum(install_finish) / sum(download_finish) * 100,
-3
-) install_finish_rate,
- sum(active) active,
- round(sum(cost) / sum(active), 3) active_cost,
- round(
-sum(active) / sum(click) * 100,
-3
-) active_rate,
- sum(register) register,
- round(sum(cost) / sum(register), 3) active_register_cost,
- round(
-sum(active_register_rate) / {day_count} * 100,
-3
-) active_register_rate,
- sum(next_day_open) next_day_open,
- round(
-sum(cost) / sum(next_day_open),
-3
-) next_day_open_cost,
- round(
-sum(next_day_open) / sum(active) * 100,
-3
-) next_day_open_rate,
- sum(
-attribution_next_day_open_cnt
-) attribution_next_day_open_cnt,
- round(
-sum(cost) / sum(
-attribution_next_day_open_cnt
-),
-3
-) attribution_next_day_open_cost,
- round(
-sum(
-attribution_next_day_open_cnt
-) / sum(active) * 100,
-3
-) attribution_next_day_open_rate,
- sum(game_addiction) game_addiction,
- round(
-sum(cost) / sum(game_addiction),
-3
-) game_addiction_cost,
- round(
-sum(game_addiction_rate) / {day_count} * 100,
-3
-) game_addiction_rate,
- sum(pay_count) pay_count,
- round(sum(cost) / sum(pay_count), 3) active_pay_cost,
- round(
-sum(pay_count) / sum(active) * 100,
-3
-) active_pay_rate,
- sum(loan_completion) loan_completion,
- round(
-sum(cost) / sum(loan_completion),
-3
-) loan_completion_cost,
- round(
-sum(loan_completion) / sum(register) * 100,
-3
-) loan_completion_rate,
- round(sum(pre_loan_credit), 3) pre_loan_credit,
- round(
-sum(cost) / sum(pre_loan_credit),
-3
-) pre_loan_credit_cost,
- sum(loan_credit) loan_credit,
- round(
-sum(cost) / sum(loan_credit),
-3
-) loan_credit_cost,
- round(
-sum(loan_credit) / sum(loan_completion) * 100,
-3
-) loan_credit_rate,
- sum(in_app_uv) in_app_uv,
- sum(in_app_detail_uv) in_app_detail_uv,
- sum(in_app_cart) in_app_cart,
- sum(in_app_pay) in_app_pay,
- sum(in_app_order) in_app_order,
- round(
-sum(
-attribution_game_pay_7d_count
-) / {day_count},
-3
-) attribution_game_pay_7d_count,
- round(
-sum(
-attribution_game_pay_7d_cost
-) / {day_count},
-3
-) attribution_game_pay_7d_cost,
- round(
-sum(
-attribution_active_pay_7d_per_count
-) / {day_count},
-3
-) attribution_active_pay_7d_per_count,
- sum(game_pay_cost) game_pay_cost,
- sum(game_pay_count) game_pay_count,
- sum(phone) phone,
- sum(form) form,
- sum(map_search) map_search,
- sum(button) button,
- sum(`view`) `view`,
- sum(download) download,
- sum(qq) qq,
- sum(lottery) lottery,
- sum(vote) vote,
- sum(message) message,
- sum(redirect) redirect,
- sum(shopping) shopping,
- sum(consult) consult,
- sum(wechat) wechat,
- sum(phone_confirm) phone_confirm,
- sum(phone_connect) phone_connect,
- sum(consult_effective) consult_effective,
- sum(coupon) coupon,
- sum(coupon_single_page) coupon_single_page,
- sum(redirect_to_shop) redirect_to_shop,
- sum(poi_collect) poi_collect,
- sum(poi_address_click) poi_address_click,
- sum(luban_order_cnt) luban_order_cnt,
- sum(luban_order_stat_amount) luban_order_stat_amount,
- sum(luban_order_roi) luban_order_roi,
- sum(luban_live_enter_cnt) luban_live_enter_cnt,
- sum(
-live_watch_one_minute_count
-) live_watch_one_minute_count,
- sum(luban_live_follow_cnt) luban_live_follow_cnt,
- sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
- sum(luban_live_comment_cnt) luban_live_comment_cnt,
- sum(luban_live_share_cnt) luban_live_share_cnt,
- sum(luban_live_gift_cnt) luban_live_gift_cnt,
- sum(luban_live_gift_amount) luban_live_gift_amount,
- sum(
-luban_live_slidecart_click_cnt
-) luban_live_slidecart_click_cnt,
- sum(
-luban_live_click_product_cnt
-) luban_live_click_product_cnt,
- sum(luban_live_pay_order_count) luban_live_pay_order_count,
- sum(
-luban_live_pay_order_stat_cost
-) luban_live_pay_order_stat_cost,
- sum(live_component_click_count) live_component_click_count,
- round(
-sum(cost) / sum(live_component_click_count),
-3
-) live_component_click_cost,
- round(
-sum(live_component_click_count) / {day_count} * 100,
-3
-) live_component_click_rate,
- sum(wechat_login_count) wechat_login_count,
- sum(
-attribution_wechat_login_30d_count
-) attribution_wechat_login_30d_count,
- round(
-sum(cost) / sum(wechat_login_count),
-3
-) wechat_login_cost,
- round(
-sum(cost) / sum(
-attribution_wechat_login_30d_count
-),
-3
-) attribution_wechat_login_30d_cost,
- sum(wechat_first_pay_count) wechat_first_pay_count,
- sum(
-attribution_wechat_first_pay_30d_count
-) attribution_wechat_first_pay_30d_count,
- round(
-sum(cost) / sum(wechat_first_pay_count),
-3
-) wechat_first_pay_cost,
- round(
-sum(cost) / sum(
-attribution_wechat_first_pay_30d_count
-),
-3
-) attribution_wechat_first_pay_30d_cost,
- round(
-sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-3
-) wechat_first_pay_rate,
- round(
-sum(
-attribution_wechat_first_pay_30d_count
-) / sum(
-attribution_wechat_login_30d_count
-) * 100,
-3
-) attribution_wechat_first_pay_30d_rate,
- sum(wechat_pay_amount) wechat_pay_amount,
- sum(
-attribution_wechat_pay_30d_amount
-) attribution_wechat_pay_30d_amount,
- sum(
-attribution_wechat_pay_30d_roi
-) attribution_wechat_pay_30d_roi,
- sum(phone_effective) phone_effective,
- sum(total_play) total_play,
- sum(valid_play) valid_play,
- round(
-sum(cost) / sum(valid_play),
-3
-) valid_play_cost,
- round(
-sum(valid_play) / sum(`show`) * 100,
-3
-) valid_play_rate,
- sum(play_25_feed_break) play_25_feed_break,
- sum(play_50_feed_break) play_50_feed_break,
- sum(play_75_feed_break) play_75_feed_break,
- sum(play_100_feed_break) play_100_feed_break,
- round(
-sum(average_play_time_per_play) / {day_count},
-3
-) average_play_time_per_play,
- round(
-sum(play_over_rate) / {day_count} * 100,
-3
-) play_over_rate,
- round(
-sum(wifi_play) / sum(total_play) * 100,
-3
-) wifi_play_rate,
- sum(wifi_play) wifi_play,
- round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
- sum(
-advanced_creative_phone_click
-) advanced_creative_phone_click,
- sum(
-advanced_creative_counsel_click
-) advanced_creative_counsel_click,
- sum(
-advanced_creative_form_click
-) advanced_creative_form_click,
- sum(
-advanced_creative_coupon_addition
-) advanced_creative_coupon_addition,
- sum(
-advanced_creative_form_submit
-) advanced_creative_form_submit,
- sum(card_show) card_show,
- sum(`share`) `share`,
- sum(`comment`) `comment`,
- sum(`like`) `like`,
- sum(follow) follow,
- sum(home_visited) home_visited,
- sum(ies_challenge_click) ies_challenge_click,
- sum(ies_music_click) ies_music_click,
- sum(location_click) location_click,
- sum(message_action) message_action,
- sum(click_landing_page) click_landing_page,
- sum(click_shopwindow) click_shopwindow,
- sum(click_website) click_website,
- sum(click_download) click_download,
- sum(click_call_dy) click_call_dy,
- sum(submit_certification_count) submit_certification_count,
- sum(approval_count) approval_count,
- sum(first_order_count) first_rental_order_count,
- sum(first_rental_order_count) first_order_count,
- sum(commute_first_pay_count) commute_first_pay_count
+               sum(`show`) `show`,
+               ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+               sum(click)click,
+               ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+               ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+               sum(`convert`)`convert`,
+               ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+               ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+               sum(deep_convert) deep_convert,
+               ifnull(round( sum(cost) / sum(deep_convert), 3),0) deep_convert_cost,
+               ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+               sum(attribution_convert)attribution_convert,
+               ifnull(round( sum(cost) / sum(attribution_convert), 3),0) attribution_convert_cost,
+               sum(attribution_deep_convert) attribution_deep_convert,
+               ifnull(round( sum(cost) / sum(attribution_deep_convert), 3),0) attribution_deep_convert_cost,
+               sum(download_start) download_start,
+               ifnull(round( sum(cost) / sum(download_start), 3),0) download_start_cost,
+               ifnull(round( sum(download_start) / sum(click), 3),0) download_start_rate,
+               sum(download_finish) download_finish,
+               ifnull(round( sum(cost) / sum(download_finish), 3),0) download_finish_cost,
+               ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+               sum(click_install)click_install,
+               sum(install_finish) install_finish,
+               ifnull(round( sum(cost) / sum(install_finish), 3),0) install_finish_cost,
+               ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+               sum(active) active,
+               ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+               ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+               sum(register)register,
+               ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+               ifnull(round(sum(active_register_rate) / {day_count} * 100,3),0) active_register_rate,
+               sum(next_day_open)next_day_open,
+               ifnull(round( sum(cost) / sum(next_day_open), 3),0) next_day_open_cost,
+               ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+               sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+               ifnull(round( sum(cost) / sum(attribution_next_day_open_cnt ), 3),0) attribution_next_day_open_cost,
+               ifnull(round(sum(attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+               sum(game_addiction) game_addiction,
+               ifnull(round( sum(cost) / sum(game_addiction), 3),0) game_addiction_cost,
+               ifnull(round(sum(game_addiction_rate) / {day_count} * 100,3),0) game_addiction_rate,
+               sum(pay_count)pay_count,
+               ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+               ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+               sum(loan_completion) loan_completion,
+               ifnull(round( sum(cost) / sum(loan_completion), 3),0) loan_completion_cost,
+               ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+               ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+               ifnull(round( sum(cost) / sum(pre_loan_credit), 3),0) pre_loan_credit_cost,
+               sum(loan_credit)loan_credit,
+               ifnull(round( sum(cost) / sum(loan_credit), 3),0) loan_credit_cost,
+               ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+               sum(in_app_uv)in_app_uv,
+               sum(in_app_detail_uv) in_app_detail_uv,
+               sum(in_app_cart) in_app_cart,
+               sum(in_app_pay) in_app_pay,
+               sum(in_app_order) in_app_order,
+               ifnull(round( sum(attribution_game_pay_7d_count) / {day_count}, 3),0) attribution_game_pay_7d_count,
+               ifnull(round( sum(attribution_game_pay_7d_cost) / {day_count}, 3),0) attribution_game_pay_7d_cost,
+               ifnull(round( sum(attribution_active_pay_7d_per_count) / {day_count}, 3),0) attribution_active_pay_7d_per_count,
+               sum(game_pay_cost)game_pay_cost,
+               sum(game_pay_count) game_pay_count,
+               sum(phone) phone,
+               sum(form) form,
+               sum(map_search) map_search,
+               sum(button) button,
+               sum(`view`) `view`,
+               sum(download)download,
+               sum(qq)qq,
+               sum(lottery)lottery,
+               sum(vote) vote,
+               sum(message)message,
+               sum(redirect)redirect,
+               sum(shopping)shopping,
+               sum(consult)consult,
+               sum(wechat) wechat,
+               sum(phone_confirm)phone_confirm,
+               sum(phone_connect)phone_connect,
+               sum(consult_effective)consult_effective,
+               sum(coupon) coupon,
+               sum(coupon_single_page) coupon_single_page,
+               sum(redirect_to_shop) redirect_to_shop,
+               sum(poi_collect)poi_collect,
+               sum(poi_address_click)poi_address_click,
+               sum(luban_order_cnt) luban_order_cnt,
+               sum(luban_order_stat_amount)luban_order_stat_amount,
+               sum(luban_order_roi) luban_order_roi,
+               sum(luban_live_enter_cnt) luban_live_enter_cnt,
+               sum(live_watch_one_minute_count) live_watch_one_minute_count,
+               sum(luban_live_follow_cnt) luban_live_follow_cnt,
+               sum(live_fans_club_join_cnt)live_fans_club_join_cnt,
+               sum(luban_live_comment_cnt) luban_live_comment_cnt,
+               sum(luban_live_share_cnt) luban_live_share_cnt,
+               sum(luban_live_gift_cnt)luban_live_gift_cnt,
+               sum(luban_live_gift_amount) luban_live_gift_amount,
+               sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+               sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+               sum(luban_live_pay_order_count) luban_live_pay_order_count,
+               sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+               sum(live_component_click_count) live_component_click_count,
+               ifnull(round( sum(cost) / sum(live_component_click_count), 3),0) live_component_click_cost,
+               ifnull(round(sum(live_component_click_count) / {day_count} * 100,3),0) live_component_click_rate,
+               sum(wechat_login_count) wechat_login_count,
+               sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_login_count), 3),0) wechat_login_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_login_30d_count ), 3),0) attribution_wechat_login_30d_cost,
+               sum(wechat_first_pay_count) wechat_first_pay_count,
+               sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+               ifnull(round( sum(cost) / sum(wechat_first_pay_count), 3),0) wechat_first_pay_cost,
+               ifnull(round( sum(cost) / sum(attribution_wechat_first_pay_30d_count ), 3),0) attribution_wechat_first_pay_30d_cost,
+               ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+               ifnull(round(sum(attribution_wechat_first_pay_30d_count) / sum(attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+               sum(wechat_pay_amount)wechat_pay_amount,
+               sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+               sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+               sum(phone_effective) phone_effective,
+               sum(total_play) total_play,
+               sum(valid_play) valid_play,
+               ifnull(round( sum(cost) / sum(valid_play), 3),0) valid_play_cost,
+               ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+               sum(play_25_feed_break) play_25_feed_break,
+               sum(play_50_feed_break) play_50_feed_break,
+               sum(play_75_feed_break) play_75_feed_break,
+               sum(play_100_feed_break)play_100_feed_break,
+               ifnull(round( sum(average_play_time_per_play) / {day_count}, 3),0) average_play_time_per_play,
+               ifnull(round(sum(play_over_rate) / {day_count} * 100,3),0) play_over_rate,
+               ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+               sum(wifi_play)wifi_play,
+               ifnull(round(sum(play_duration_sum) / {day_count}, 3),0) play_duration_sum,
+               sum(advanced_creative_phone_click) advanced_creative_phone_click,
+               sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+               sum(advanced_creative_form_click) advanced_creative_form_click,
+               sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+               sum(advanced_creative_form_submit) advanced_creative_form_submit,
+               sum(card_show)card_show,
+               sum(`share`)`share`,
+               sum(`comment`)`comment`,
+               sum(`like`) `like`,
+               sum(follow) follow,
+               sum(home_visited) home_visited,
+               sum(ies_challenge_click)ies_challenge_click,
+               sum(ies_music_click) ies_music_click,
+               sum(location_click) location_click,
+               sum(message_action) message_action,
+               sum(click_landing_page) click_landing_page,
+               sum(click_shopwindow) click_shopwindow,
+               sum(click_website)click_website,
+               sum(click_download) click_download,
+               sum(click_call_dy)click_call_dy,
+               sum(submit_certification_count) submit_certification_count,
+               sum(approval_count) approval_count,
+               sum(first_order_count)first_rental_order_count,
+               sum(first_rental_order_count) first_order_count,
+               sum(commute_first_pay_count)commute_first_pay_count
 FROM
 (
 SELECT

+ 180 - 376
Apietl/bytedance_etl/Q4Task/AppBytedanceVideoReportBusi.py

@@ -265,389 +265,190 @@ SELECT concat(date_format(date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY)
        video.`video_url`,
        cmi.`cover_url`
 FROM (
-         SELECT advertiser_id                        account_id,
+         SELECT advertiser_id    account_id,
                 material_id,
                 image_mode,
                 inventory,
-                sum(cost)                            cost,
-                sum(`show`)                          `show`,
-                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-                sum(click)                           click,
-                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-                round(
-                        sum(click) / sum(`show`) * 100,
-                        3
-                    )                                ctr,
-                sum(`convert`)                       `convert`,
-                round(sum(cost) / sum(`convert`), 3) convert_cost,
-                round(
-                        sum(`convert`) / sum(click) * 100,
-                        3
-                    )                                convert_rate,
-                sum(deep_convert)                    deep_convert,
-                round(
-                        sum(cost) / sum(deep_convert),
-                        3
-                    )                                deep_convert_cost,
-                round(
-                        sum(deep_convert) / sum(`convert`) * 100,
-                        3
-                    )                                deep_convert_rate,
-                sum(attribution_convert)             attribution_convert,
-                round(
-                        sum(cost) / sum(attribution_convert),
-                        3
-                    )                                attribution_convert_cost,
-                sum(attribution_deep_convert)        attribution_deep_convert,
-                round(
-                        sum(cost) / sum(attribution_deep_convert),
-                        3
-                    )                                attribution_deep_convert_cost,
-                sum(download_start)                  download_start,
-                round(
-                        sum(cost) / sum(download_start),
-                        3
-                    )                                download_start_cost,
-                round(
-                        sum(download_start) / sum(click),
-                        3
-                    )                                download_start_rate,
-                sum(download_finish)                 download_finish,
-                round(
-                        sum(cost) / sum(download_finish),
-                        3
-                    )                                download_finish_cost,
-                round(
-                        sum(download_finish) / sum(download_start) * 100,
-                        3
-                    )                                download_finish_rate,
-                sum(click_install)                   click_install,
-                sum(install_finish)                  install_finish,
-                round(
-                        sum(cost) / sum(install_finish),
-                        3
-                    )                                install_finish_cost,
-                round(
-                        sum(install_finish) / sum(download_finish) * 100,
-                        3
-                    )                                install_finish_rate,
-                sum(active)                          active,
-                round(sum(cost) / sum(active), 3)    active_cost,
-                round(
-                        sum(active) / sum(click) * 100,
-                        3
-                    )                                active_rate,
-                sum(register)                        register,
-                round(sum(cost) / sum(register), 3)  active_register_cost,
-                round(
-                        sum(active_register_rate) / {day_count} * 100,
-                        3
-                    )                                active_register_rate,
-                sum(active_pay_amount)               active_pay_amount,
-                sum(next_day_open)                   next_day_open,
-                round(
-                        sum(cost) / sum(next_day_open),
-                        3
-                    )                                next_day_open_cost,
-                round(
-                        sum(next_day_open) / sum(active) * 100,
-                        3
-                    )                                next_day_open_rate,
-                sum(
-                        attribution_next_day_open_cnt
-                    )                                attribution_next_day_open_cnt,
-                round(
-                            sum(cost) / sum(
-                                attribution_next_day_open_cnt
-                            ),
-                            3
-                    )                                attribution_next_day_open_cost,
-                round(
-                                sum(
-                                        attribution_next_day_open_cnt
-                                    ) / sum(active) * 100,
-                                3
-                    )                                attribution_next_day_open_rate,
-                sum(game_addiction)                  game_addiction,
-                round(
-                        sum(cost) / sum(game_addiction),
-                        3
-                    )                                game_addiction_cost,
-                round(
-                        sum(game_addiction_rate) / {day_count} * 100,
-                        3
-                    )                                game_addiction_rate,
-                sum(pay_count)                       pay_count,
-                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-                round(
-                        sum(pay_count) / sum(active) * 100,
-                        3
-                    )                                active_pay_rate,
-                sum(loan_completion)                 loan_completion,
-                round(
-                        sum(cost) / sum(loan_completion),
-                        3
-                    )                                loan_completion_cost,
-                round(
-                        sum(loan_completion) / sum(register) * 100,
-                        3
-                    )                                loan_completion_rate,
-                round(sum(pre_loan_credit), 3)       pre_loan_credit,
-                round(
-                        sum(cost) / sum(pre_loan_credit),
-                        3
-                    )                                pre_loan_credit_cost,
-                sum(loan_credit)                     loan_credit,
-                round(
-                        sum(cost) / sum(loan_credit),
-                        3
-                    )                                loan_credit_cost,
-                round(
-                        sum(loan_credit) / sum(loan_completion) * 100,
-                        3
-                    )                                loan_credit_rate,
-                sum(in_app_uv)                       in_app_uv,
-                sum(in_app_detail_uv)                in_app_detail_uv,
-                sum(in_app_cart)                     in_app_cart,
-                sum(in_app_pay)                      in_app_pay,
-                sum(in_app_order)                    in_app_order,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_count
-                                ) / {day_count},
-                            3
-                    )                                attribution_game_pay_7d_count,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_cost
-                                ) / {day_count},
-                            3
-                    )                                attribution_game_pay_7d_cost,
-                round(
-                            sum(
-                                    attribution_active_pay_7d_per_count
-                                ) / {day_count},
-                            3
-                    )                                attribution_active_pay_7d_per_count,
-                sum(game_pay_cost)                   game_pay_cost,
-                sum(game_pay_count)                  game_pay_count,
-                sum(phone)                           phone,
-                sum(form)                            form,
-                sum(map_search)                      map_search,
-                sum(button)                          button,
-                sum(`view`)                          `view`,
-                sum(download)                        download,
-                sum(qq)                              qq,
-                sum(lottery)                         lottery,
-                sum(vote)                            vote,
-                sum(message)                         message,
-                sum(redirect)                        redirect,
-                sum(shopping)                        shopping,
-                sum(consult)                         consult,
-                sum(wechat)                          wechat,
-                sum(phone_confirm)                   phone_confirm,
-                sum(phone_connect)                   phone_connect,
-                sum(consult_effective)               consult_effective,
-                sum(coupon)                          coupon,
-                sum(coupon_single_page)              coupon_single_page,
-                sum(redirect_to_shop)                redirect_to_shop,
-                sum(poi_collect)                     poi_collect,
-                sum(poi_address_click)               poi_address_click,
-                sum(luban_order_cnt)                 luban_order_cnt,
-                sum(luban_order_stat_amount)         luban_order_stat_amount,
-                sum(luban_order_roi)                 luban_order_roi,
-                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-                sum(
-                        live_watch_one_minute_count
-                    )                                live_watch_one_minute_count,
-                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-                sum(luban_live_share_cnt)            luban_live_share_cnt,
-                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-                sum(luban_live_gift_amount)          luban_live_gift_amount,
-                sum(
-                        luban_live_slidecart_click_cnt
-                    )                                luban_live_slidecart_click_cnt,
-                sum(
-                        luban_live_click_product_cnt
-                    )                                luban_live_click_product_cnt,
-                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-                sum(
-                        luban_live_pay_order_stat_cost
-                    )                                luban_live_pay_order_stat_cost,
-                sum(wechat_login_count)              wechat_login_count,
-                sum(
-                        attribution_wechat_login_30d_count
-                    )                                attribution_wechat_login_30d_count,
-                round(
-                        sum(cost) / sum(wechat_login_count),
-                        3
-                    )                                wechat_login_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_login_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_login_30d_cost,
-                sum(wechat_first_pay_count)          wechat_first_pay_count,
-                sum(
-                        attribution_wechat_first_pay_30d_count
-                    )                                attribution_wechat_first_pay_30d_count,
-                round(
-                        sum(cost) / sum(wechat_first_pay_count),
-                        3
-                    )                                wechat_first_pay_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_first_pay_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_first_pay_30d_cost,
-                round(
-                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-                        3
-                    )                                wechat_first_pay_rate,
-                round(
-                                sum(
-                                        attribution_wechat_first_pay_30d_count
-                                    ) / sum(
-                                        attribution_wechat_login_30d_count
-                                    ) * 100,
-                                3
-                    )                                attribution_wechat_first_pay_30d_rate,
-                sum(wechat_pay_amount)               wechat_pay_amount,
-                sum(
-                        attribution_wechat_pay_30d_amount
-                    )                                attribution_wechat_pay_30d_amount,
-                sum(
-                        attribution_wechat_pay_30d_roi
-                    )                                attribution_wechat_pay_30d_roi,
-                sum(phone_effective)                 phone_effective,
-                sum(total_play)                      total_play,
-                sum(valid_play)                      valid_play,
-                round(
-                        sum(cost) / sum(valid_play),
-                        3
-                    )                                valid_play_cost,
-                round(
-                        sum(valid_play) / sum(`show`) * 100,
-                        3
-                    )                                valid_play_rate,
-                sum(play_25_feed_break)              play_25_feed_break,
-                sum(play_50_feed_break)              play_50_feed_break,
-                sum(play_75_feed_break)              play_75_feed_break,
-                sum(play_100_feed_break)             play_100_feed_break,
-                round(
-                        sum(average_play_time_per_play) / {day_count},
-                        3
-                    )                                average_play_time_per_play,
-                round(
-                        sum(play_over_rate) / {day_count} * 100,
-                        3
-                    )                                play_over_rate,
-                round(
-                        sum(wifi_play) / sum(total_play) * 100,
-                        3
-                    )                                wifi_play_rate,
-                sum(wifi_play)                       wifi_play,
-                round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-                sum(
-                        advanced_creative_phone_click
-                    )                                advanced_creative_phone_click,
-                sum(
-                        advanced_creative_counsel_click
-                    )                                advanced_creative_counsel_click,
-                sum(
-                        advanced_creative_form_click
-                    )                                advanced_creative_form_click,
-                sum(
-                        advanced_creative_coupon_addition
-                    )                                advanced_creative_coupon_addition,
-                sum(
-                        advanced_creative_form_submit
-                    )                                advanced_creative_form_submit,
-                sum(card_show)                       card_show,
-                sum(`share`)                         `share`,
-                sum(`comment`)                       `comment`,
-                sum(`like`)                          `like`,
-                sum(follow)                          follow,
-                sum(home_visited)                    home_visited,
-                sum(ies_challenge_click)             ies_challenge_click,
-                sum(ies_music_click)                 ies_music_click,
-                sum(location_click)                  location_click,
-                sum(message_action)                  message_action,
-                sum(click_landing_page)              click_landing_page,
-                sum(click_shopwindow)                click_shopwindow,
-                sum(click_website)                   click_website,
-                sum(click_download)                  click_download,
-                sum(click_call_dy)                   click_call_dy,
-                sum(cpc)                             cpc,
-                sum(cpm)                             cpm,
-                sum(cpa)                             cpa,
-                round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
-                round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
-                round(
-                        sum(round(play_duration_10s)) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_10s_rate,
-                round(
-                        sum(play_50_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_50_feed_break_rate,
-                round(
-                        sum(play_25_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_25_feed_break_rate,
-                round(
-                        sum(play_duration_5s_rate) / {day_count},
-                        3
-                    )                                play_duration_5s_rate,
-                round(
-                        sum(play_duration_2s) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_2s_rate,
-                round(
-                        sum(average_play_progress) / {day_count},
-                        3
-                    )                                average_play_progress,
-                round(
-                        sum(play_100_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_100_feed_break_rate,
-                round(
-                        sum(play_duration_3s) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_3s_rate,
-                round(
-                        sum(play_75_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_75_feed_break_rate,
-                sum(play_duration)                   play_duration,
-                sum(play_duration_3s)                play_duration_3s,
-                sum(play_duration_2s)                play_duration_2s,
-                sum(play_duration_10s)               play_duration_10s,
-                round(
-                        sum(average_video_play) / {day_count},
-                        3
-                    )                                average_video_play,
-                sum(avg_rank)                        avg_rank,
-                sum(submit_certification_count)      submit_certification_count,
-                sum(approval_count)                  approval_count,
-                sum(first_order_count)               first_rental_order_count,
-                sum(first_rental_order_count)        first_order_count,
-                sum(commute_first_pay_count)         commute_first_pay_count
+          sum(cost) cost,
+          sum(`show`) `show`,
+          ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+          sum(click) click,
+          ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+          ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+          sum(`convert`) `convert`,
+          ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+          ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+          sum(deep_convert) deep_convert,
+          ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
+          ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+          sum(attribution_convert) attribution_convert,
+          ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
+          sum(attribution_deep_convert) attribution_deep_convert,
+          ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
+          sum(download_start) download_start,
+          ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
+          ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
+          sum(download_finish) download_finish,
+          ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
+          ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+          sum(click_install) click_install,
+          sum(install_finish) install_finish,
+          ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
+          ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+          sum(active) active,
+          ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+          ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+          sum(register) register,
+          ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+          ifnull(round(sum(active_register_rate) /{day_count} * 100,3),0) active_register_rate,
+          sum(active_pay_amount) active_pay_amount,
+          sum(next_day_open) next_day_open,
+          ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
+          ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+          sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+          ifnull(round(sum(cost) / sum(	attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
+          ifnull(round(sum(	attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+          sum(game_addiction) game_addiction,
+          ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
+          ifnull(round(sum(game_addiction_rate) /{day_count} * 100,3),0) game_addiction_rate,
+          sum(pay_count) pay_count,
+          ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+          ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+          sum(loan_completion) loan_completion,
+          ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
+          ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+          ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+          ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
+          sum(loan_credit) loan_credit,
+          ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
+          ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+          sum(in_app_uv) in_app_uv,
+          sum(in_app_detail_uv) in_app_detail_uv,
+          sum(in_app_cart) in_app_cart,
+          sum(in_app_pay) in_app_pay,
+          sum(in_app_order) in_app_order,
+          ifnull(round(sum(	attribution_game_pay_7d_count) /{day_count}, 3),0) attribution_game_pay_7d_count,
+          ifnull(round(sum(	attribution_game_pay_7d_cost) /{day_count}, 3),0) attribution_game_pay_7d_cost,
+          ifnull(round(sum(	attribution_active_pay_7d_per_count) /{day_count}, 3),0) attribution_active_pay_7d_per_count,
+          sum(game_pay_cost) game_pay_cost,
+          sum(game_pay_count) game_pay_count,
+          sum(phone) phone,
+          sum(form) form,
+          sum(map_search) map_search,
+          sum(button) button,
+          sum(`view`) `view`,
+          sum(download) download,
+          sum(qq) qq,
+          sum(lottery) lottery,
+          sum(vote) vote,
+          sum(message) message,
+          sum(redirect) redirect,
+          sum(shopping) shopping,
+          sum(consult) consult,
+          sum(wechat) wechat,
+          sum(phone_confirm) phone_confirm,
+          sum(phone_connect) phone_connect,
+          sum(consult_effective) consult_effective,
+          sum(coupon) coupon,
+          sum(coupon_single_page) coupon_single_page,
+          sum(redirect_to_shop) redirect_to_shop,
+          sum(poi_collect) poi_collect,
+          sum(poi_address_click) poi_address_click,
+          sum(luban_order_cnt) luban_order_cnt,
+          sum(luban_order_stat_amount) luban_order_stat_amount,
+          sum(luban_order_roi) luban_order_roi,
+          sum(luban_live_enter_cnt) luban_live_enter_cnt,
+          sum(live_watch_one_minute_count) live_watch_one_minute_count,
+          sum(luban_live_follow_cnt) luban_live_follow_cnt,
+          sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+          sum(luban_live_comment_cnt) luban_live_comment_cnt,
+          sum(luban_live_share_cnt) luban_live_share_cnt,
+          sum(luban_live_gift_cnt) luban_live_gift_cnt,
+          sum(luban_live_gift_amount) luban_live_gift_amount,
+          sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+          sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+          sum(luban_live_pay_order_count) luban_live_pay_order_count,
+          sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+          sum(wechat_login_count) wechat_login_count,
+          sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
+          sum(wechat_first_pay_count) wechat_first_pay_count,
+          sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
+          ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+          ifnull(round(sum(	attribution_wechat_first_pay_30d_count) / sum(	attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+          sum(wechat_pay_amount) wechat_pay_amount,
+          sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+          sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+          sum(phone_effective) phone_effective,
+          sum(total_play) total_play,
+          sum(valid_play) valid_play,
+          ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
+          ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+          sum(play_25_feed_break) play_25_feed_break,
+          sum(play_50_feed_break) play_50_feed_break,
+          sum(play_75_feed_break) play_75_feed_break,
+          sum(play_100_feed_break) play_100_feed_break,
+          ifnull(round(sum(average_play_time_per_play) /{day_count}, 3),0) average_play_time_per_play,
+          ifnull(round(sum(play_over_rate) /{day_count} * 100,3),0) play_over_rate,
+          ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+          sum(wifi_play) wifi_play,
+          ifnull(round(sum(play_duration_sum) /{day_count}, 3),0) play_duration_sum,
+          sum(advanced_creative_phone_click) advanced_creative_phone_click,
+          sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+          sum(advanced_creative_form_click) advanced_creative_form_click,
+          sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+          sum(advanced_creative_form_submit) advanced_creative_form_submit,
+          sum(card_show) card_show,
+          sum(`share`) `share`,
+          sum(`comment`) `comment`,
+          sum(`like`) `like`,
+          sum(follow) follow,
+          sum(home_visited) home_visited,
+          sum(ies_challenge_click) ies_challenge_click,
+          sum(ies_music_click) ies_music_click,
+          sum(location_click) location_click,
+          sum(message_action) message_action,
+          sum(click_landing_page) click_landing_page,
+          sum(click_shopwindow) click_shopwindow,
+          sum(click_website) click_website,
+          sum(click_download) click_download,
+          sum(click_call_dy) click_call_dy,
+          sum(cpc) cpc,
+          sum(cpm) cpm,
+          sum(cpa) cpa,
+          ifnull(round(sum(interact_per_cost) /{day_count}, 3),0) interact_per_cost,
+          ifnull(round(sum(convert_show_rate) /{day_count}, 3),0) convert_show_rate,
+          ifnull(round(sum(play_duration_10s) / sum(total_play) * 100,3),0) play_duration_10s_rate,
+          ifnull(round(sum(play_50_feed_break) / sum(total_play) * 100,3),0) play_50_feed_break_rate,
+          ifnull(round(sum(play_25_feed_break) / sum(total_play) * 100,3),0) play_25_feed_break_rate,
+          ifnull(round(sum(play_duration_5s_rate) /{day_count}, 3),0) play_duration_5s_rate,
+          ifnull(round(sum(play_duration_2s) / sum(total_play) * 100,3),0) play_duration_2s_rate,
+          ifnull(round(sum(average_play_progress) /{day_count}, 3),0) average_play_progress,
+          ifnull(round(sum(play_100_feed_break) / sum(total_play) * 100,3),0) play_100_feed_break_rate,
+          ifnull(round(sum(play_duration_3s) / sum(total_play) * 100,3),0) play_duration_3s_rate,
+          ifnull(round(sum(play_75_feed_break) / sum(total_play) * 100,3),0) play_75_feed_break_rate,
+          sum(play_duration) play_duration,
+          sum(play_duration_3s) play_duration_3s,
+          sum(play_duration_2s) play_duration_2s,
+          sum(play_duration_10s) play_duration_10s,
+          ifnull(round(sum(average_video_play) /{day_count}, 3),0) average_video_play,
+          sum(avg_rank) avg_rank,
+          sum(submit_certification_count) submit_certification_count,
+          sum(approval_count) approval_count,
+          sum(first_order_count) first_rental_order_count,
+          sum(first_rental_order_count) first_order_count,
+          sum(commute_first_pay_count) commute_first_pay_count
          FROM media_api.bytedance_material_report_daily zhubiao
          WHERE image_mode IN (
                               'CREATIVE_IMAGE_MODE_VIDEO',
                               'CREATIVE_IMAGE_MODE_VIDEO_VERTICAL',
                               'CREATIVE_IMAGE_MODE_UNION_SPLASH_VIDEO'
              )
-           AND stat_datetime >= date_format(
-                 date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),
-                 '%Y%m%d'
-             )
-             and advertiser_id={account_id}
+           AND stat_datetime >= date_format( date_sub({date_time}, INTERVAL ({day_count} -1 )  DAY),'%Y%m%d') 
+           and advertiser_id={account_id}
          GROUP BY advertiser_id,
                   material_id,
                   image_mode,
@@ -657,7 +458,8 @@ FROM (
                     from `media_api`.bytedance_file_video_get and advertiser_id={account_id}
                     group by advertiser_id, signature, material_id, filename, video_url) video
                    ON report.account_id = video.advertiser_id AND report.material_id = video.material_id
-         LEFT JOIN `jeecg-boot`.ctop_material_info cmi ON video.signature = cmi.code
+         LEFT JOIN (select  code,material_name from `jeecg-boot`.ctop_material_info where status=1) cmi 
+         ON video.signature = cmi.code
          LEFT JOIN (select material_id, clip_id, shot_id, plan_id, leader_id
                     from (
                              select material_id,
@@ -680,7 +482,9 @@ FROM (
          LEFT JOIN `jeecg-boot`.sys_user plan ON plan.id = cma.plan_id
          LEFT JOIN `jeecg-boot`.sys_user leader ON leader.id = cma.leader_id
          LEFT JOIN `jeecg-boot`.user_company up ON up.user_id = cma.clip_id
-         where cua.account_id = {account_id};""".format(date_time=self.date_time,
+         where cua.account_id = {account_id};
+         
+    """.format(date_time=self.date_time,
                                                         day_count=self.day_count,
                                                         account_id=account_id[0])
                     TidbConn.upsert(conn=self.conn, sql_buff=sql)

+ 175 - 370
Apietl/bytedance_etl/Q4Task/AppBytedanceVideoReportBusiMonth.py

@@ -265,378 +265,182 @@ SELECT date_format({date_time},'%Y%m')         stat_mon,
        video.`video_url`,
        cmi.`cover_url`
 FROM (
-         SELECT advertiser_id                        account_id,
+          SELECT advertiser_id    account_id,
                 material_id,
                 image_mode,
                 inventory,
-                sum(cost)                            cost,
-                sum(`show`)                          `show`,
-                round(sum(cost) / sum(`show`), 3)    avg_show_cost,
-                sum(click)                           click,
-                round(sum(cost) / sum(`click`), 3)   avg_click_cost,
-                round(
-                        sum(click) / sum(`show`) * 100,
-                        3
-                    )                                ctr,
-                sum(`convert`)                       `convert`,
-                round(sum(cost) / sum(`convert`), 3) convert_cost,
-                round(
-                        sum(`convert`) / sum(click) * 100,
-                        3
-                    )                                convert_rate,
-                sum(deep_convert)                    deep_convert,
-                round(
-                        sum(cost) / sum(deep_convert),
-                        3
-                    )                                deep_convert_cost,
-                round(
-                        sum(deep_convert) / sum(`convert`) * 100,
-                        3
-                    )                                deep_convert_rate,
-                sum(attribution_convert)             attribution_convert,
-                round(
-                        sum(cost) / sum(attribution_convert),
-                        3
-                    )                                attribution_convert_cost,
-                sum(attribution_deep_convert)        attribution_deep_convert,
-                round(
-                        sum(cost) / sum(attribution_deep_convert),
-                        3
-                    )                                attribution_deep_convert_cost,
-                sum(download_start)                  download_start,
-                round(
-                        sum(cost) / sum(download_start),
-                        3
-                    )                                download_start_cost,
-                round(
-                        sum(download_start) / sum(click),
-                        3
-                    )                                download_start_rate,
-                sum(download_finish)                 download_finish,
-                round(
-                        sum(cost) / sum(download_finish),
-                        3
-                    )                                download_finish_cost,
-                round(
-                        sum(download_finish) / sum(download_start) * 100,
-                        3
-                    )                                download_finish_rate,
-                sum(click_install)                   click_install,
-                sum(install_finish)                  install_finish,
-                round(
-                        sum(cost) / sum(install_finish),
-                        3
-                    )                                install_finish_cost,
-                round(
-                        sum(install_finish) / sum(download_finish) * 100,
-                        3
-                    )                                install_finish_rate,
-                sum(active)                          active,
-                round(sum(cost) / sum(active), 3)    active_cost,
-                round(
-                        sum(active) / sum(click) * 100,
-                        3
-                    )                                active_rate,
-                sum(register)                        register,
-                round(sum(cost) / sum(register), 3)  active_register_cost,
-                round(
-                        sum(active_register_rate) / {day_count} * 100,
-                        3
-                    )                                active_register_rate,
-                sum(active_pay_amount)               active_pay_amount,
-                sum(next_day_open)                   next_day_open,
-                round(
-                        sum(cost) / sum(next_day_open),
-                        3
-                    )                                next_day_open_cost,
-                round(
-                        sum(next_day_open) / sum(active) * 100,
-                        3
-                    )                                next_day_open_rate,
-                sum(
-                        attribution_next_day_open_cnt
-                    )                                attribution_next_day_open_cnt,
-                round(
-                            sum(cost) / sum(
-                                attribution_next_day_open_cnt
-                            ),
-                            3
-                    )                                attribution_next_day_open_cost,
-                round(
-                                sum(
-                                        attribution_next_day_open_cnt
-                                    ) / sum(active) * 100,
-                                3
-                    )                                attribution_next_day_open_rate,
-                sum(game_addiction)                  game_addiction,
-                round(
-                        sum(cost) / sum(game_addiction),
-                        3
-                    )                                game_addiction_cost,
-                round(
-                        sum(game_addiction_rate) / {day_count} * 100,
-                        3
-                    )                                game_addiction_rate,
-                sum(pay_count)                       pay_count,
-                round(sum(cost) / sum(pay_count), 3) active_pay_cost,
-                round(
-                        sum(pay_count) / sum(active) * 100,
-                        3
-                    )                                active_pay_rate,
-                sum(loan_completion)                 loan_completion,
-                round(
-                        sum(cost) / sum(loan_completion),
-                        3
-                    )                                loan_completion_cost,
-                round(
-                        sum(loan_completion) / sum(register) * 100,
-                        3
-                    )                                loan_completion_rate,
-                round(sum(pre_loan_credit), 3)       pre_loan_credit,
-                round(
-                        sum(cost) / sum(pre_loan_credit),
-                        3
-                    )                                pre_loan_credit_cost,
-                sum(loan_credit)                     loan_credit,
-                round(
-                        sum(cost) / sum(loan_credit),
-                        3
-                    )                                loan_credit_cost,
-                round(
-                        sum(loan_credit) / sum(loan_completion) * 100,
-                        3
-                    )                                loan_credit_rate,
-                sum(in_app_uv)                       in_app_uv,
-                sum(in_app_detail_uv)                in_app_detail_uv,
-                sum(in_app_cart)                     in_app_cart,
-                sum(in_app_pay)                      in_app_pay,
-                sum(in_app_order)                    in_app_order,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_count
-                                ) / {day_count},
-                            3
-                    )                                attribution_game_pay_7d_count,
-                round(
-                            sum(
-                                    attribution_game_pay_7d_cost
-                                ) / {day_count},
-                            3
-                    )                                attribution_game_pay_7d_cost,
-                round(
-                            sum(
-                                    attribution_active_pay_7d_per_count
-                                ) / {day_count},
-                            3
-                    )                                attribution_active_pay_7d_per_count,
-                sum(game_pay_cost)                   game_pay_cost,
-                sum(game_pay_count)                  game_pay_count,
-                sum(phone)                           phone,
-                sum(form)                            form,
-                sum(map_search)                      map_search,
-                sum(button)                          button,
-                sum(`view`)                          `view`,
-                sum(download)                        download,
-                sum(qq)                              qq,
-                sum(lottery)                         lottery,
-                sum(vote)                            vote,
-                sum(message)                         message,
-                sum(redirect)                        redirect,
-                sum(shopping)                        shopping,
-                sum(consult)                         consult,
-                sum(wechat)                          wechat,
-                sum(phone_confirm)                   phone_confirm,
-                sum(phone_connect)                   phone_connect,
-                sum(consult_effective)               consult_effective,
-                sum(coupon)                          coupon,
-                sum(coupon_single_page)              coupon_single_page,
-                sum(redirect_to_shop)                redirect_to_shop,
-                sum(poi_collect)                     poi_collect,
-                sum(poi_address_click)               poi_address_click,
-                sum(luban_order_cnt)                 luban_order_cnt,
-                sum(luban_order_stat_amount)         luban_order_stat_amount,
-                sum(luban_order_roi)                 luban_order_roi,
-                sum(luban_live_enter_cnt)            luban_live_enter_cnt,
-                sum(
-                        live_watch_one_minute_count
-                    )                                live_watch_one_minute_count,
-                sum(luban_live_follow_cnt)           luban_live_follow_cnt,
-                sum(live_fans_club_join_cnt)         live_fans_club_join_cnt,
-                sum(luban_live_comment_cnt)          luban_live_comment_cnt,
-                sum(luban_live_share_cnt)            luban_live_share_cnt,
-                sum(luban_live_gift_cnt)             luban_live_gift_cnt,
-                sum(luban_live_gift_amount)          luban_live_gift_amount,
-                sum(
-                        luban_live_slidecart_click_cnt
-                    )                                luban_live_slidecart_click_cnt,
-                sum(
-                        luban_live_click_product_cnt
-                    )                                luban_live_click_product_cnt,
-                sum(luban_live_pay_order_count)      luban_live_pay_order_count,
-                sum(
-                        luban_live_pay_order_stat_cost
-                    )                                luban_live_pay_order_stat_cost,
-                sum(wechat_login_count)              wechat_login_count,
-                sum(
-                        attribution_wechat_login_30d_count
-                    )                                attribution_wechat_login_30d_count,
-                round(
-                        sum(cost) / sum(wechat_login_count),
-                        3
-                    )                                wechat_login_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_login_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_login_30d_cost,
-                sum(wechat_first_pay_count)          wechat_first_pay_count,
-                sum(
-                        attribution_wechat_first_pay_30d_count
-                    )                                attribution_wechat_first_pay_30d_count,
-                round(
-                        sum(cost) / sum(wechat_first_pay_count),
-                        3
-                    )                                wechat_first_pay_cost,
-                round(
-                            sum(cost) / sum(
-                                attribution_wechat_first_pay_30d_count
-                            ),
-                            3
-                    )                                attribution_wechat_first_pay_30d_cost,
-                round(
-                        sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,
-                        3
-                    )                                wechat_first_pay_rate,
-                round(
-                                sum(
-                                        attribution_wechat_first_pay_30d_count
-                                    ) / sum(
-                                        attribution_wechat_login_30d_count
-                                    ) * 100,
-                                3
-                    )                                attribution_wechat_first_pay_30d_rate,
-                sum(wechat_pay_amount)               wechat_pay_amount,
-                sum(
-                        attribution_wechat_pay_30d_amount
-                    )                                attribution_wechat_pay_30d_amount,
-                sum(
-                        attribution_wechat_pay_30d_roi
-                    )                                attribution_wechat_pay_30d_roi,
-                sum(phone_effective)                 phone_effective,
-                sum(total_play)                      total_play,
-                sum(valid_play)                      valid_play,
-                round(
-                        sum(cost) / sum(valid_play),
-                        3
-                    )                                valid_play_cost,
-                round(
-                        sum(valid_play) / sum(`show`) * 100,
-                        3
-                    )                                valid_play_rate,
-                sum(play_25_feed_break)              play_25_feed_break,
-                sum(play_50_feed_break)              play_50_feed_break,
-                sum(play_75_feed_break)              play_75_feed_break,
-                sum(play_100_feed_break)             play_100_feed_break,
-                round(
-                        sum(average_play_time_per_play) / {day_count},
-                        3
-                    )                                average_play_time_per_play,
-                round(
-                        sum(play_over_rate) / {day_count} * 100,
-                        3
-                    )                                play_over_rate,
-                round(
-                        sum(wifi_play) / sum(total_play) * 100,
-                        3
-                    )                                wifi_play_rate,
-                sum(wifi_play)                       wifi_play,
-                round(sum(play_duration_sum) / {day_count}, 3) play_duration_sum,
-                sum(
-                        advanced_creative_phone_click
-                    )                                advanced_creative_phone_click,
-                sum(
-                        advanced_creative_counsel_click
-                    )                                advanced_creative_counsel_click,
-                sum(
-                        advanced_creative_form_click
-                    )                                advanced_creative_form_click,
-                sum(
-                        advanced_creative_coupon_addition
-                    )                                advanced_creative_coupon_addition,
-                sum(
-                        advanced_creative_form_submit
-                    )                                advanced_creative_form_submit,
-                sum(card_show)                       card_show,
-                sum(`share`)                         `share`,
-                sum(`comment`)                       `comment`,
-                sum(`like`)                          `like`,
-                sum(follow)                          follow,
-                sum(home_visited)                    home_visited,
-                sum(ies_challenge_click)             ies_challenge_click,
-                sum(ies_music_click)                 ies_music_click,
-                sum(location_click)                  location_click,
-                sum(message_action)                  message_action,
-                sum(click_landing_page)              click_landing_page,
-                sum(click_shopwindow)                click_shopwindow,
-                sum(click_website)                   click_website,
-                sum(click_download)                  click_download,
-                sum(click_call_dy)                   click_call_dy,
-                sum(cpc)                             cpc,
-                sum(cpm)                             cpm,
-                sum(cpa)                             cpa,
-                round(sum(interact_per_cost) / {day_count}, 3) interact_per_cost,
-                round(sum(convert_show_rate) / {day_count}, 3) convert_show_rate,
-                round(
-                        sum(round(play_duration_10s)) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_10s_rate,
-                round(
-                        sum(play_50_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_50_feed_break_rate,
-                round(
-                        sum(play_25_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_25_feed_break_rate,
-                round(
-                        sum(play_duration_5s_rate) / {day_count},
-                        3
-                    )                                play_duration_5s_rate,
-                round(
-                        sum(play_duration_2s) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_2s_rate,
-                round(
-                        sum(average_play_progress) / {day_count},
-                        3
-                    )                                average_play_progress,
-                round(
-                        sum(play_100_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_100_feed_break_rate,
-                round(
-                        sum(play_duration_3s) / sum(total_play) * 100,
-                        3
-                    )                                play_duration_3s_rate,
-                round(
-                        sum(play_75_feed_break) / sum(total_play) * 100,
-                        3
-                    )                                play_75_feed_break_rate,
-                sum(play_duration)                   play_duration,
-                sum(play_duration_3s)                play_duration_3s,
-                sum(play_duration_2s)                play_duration_2s,
-                sum(play_duration_10s)               play_duration_10s,
-                round(
-                        sum(average_video_play) / {day_count},
-                        3
-                    )                                average_video_play,
-                sum(avg_rank)                        avg_rank,
-                sum(submit_certification_count)      submit_certification_count,
-                sum(approval_count)                  approval_count,
-                sum(first_order_count)               first_rental_order_count,
-                sum(first_rental_order_count)        first_order_count,
-                sum(commute_first_pay_count)         commute_first_pay_count
+          sum(cost) cost,
+          sum(`show`) `show`,
+          ifnull(round(sum(cost) / sum(`show`), 3),0) avg_show_cost,
+          sum(click) click,
+          ifnull(round(sum(cost) / sum(`click`), 3),0) avg_click_cost,
+          ifnull(round(sum(click) / sum(`show`) * 100,3),0) ctr,
+          sum(`convert`) `convert`,
+          ifnull(round(sum(cost) / sum(`convert`), 3),0) convert_cost,
+          ifnull(round(sum(`convert`) / sum(click) * 100,3),0) convert_rate,
+          sum(deep_convert) deep_convert,
+          ifnull(round(sum(cost) / sum(deep_convert),3),0) deep_convert_cost,
+          ifnull(round(sum(deep_convert) / sum(`convert`) * 100,3),0) deep_convert_rate,
+          sum(attribution_convert) attribution_convert,
+          ifnull(round(sum(cost) / sum(attribution_convert),3),0) attribution_convert_cost,
+          sum(attribution_deep_convert) attribution_deep_convert,
+          ifnull(round(sum(cost) / sum(attribution_deep_convert),3),0) attribution_deep_convert_cost,
+          sum(download_start) download_start,
+          ifnull(round(sum(cost) / sum(download_start),3),0) download_start_cost,
+          ifnull(round(sum(download_start) / sum(click),3),0) download_start_rate,
+          sum(download_finish) download_finish,
+          ifnull(round(sum(cost) / sum(download_finish),3),0) download_finish_cost,
+          ifnull(round(sum(download_finish) / sum(download_start) * 100,3),0) download_finish_rate,
+          sum(click_install) click_install,
+          sum(install_finish) install_finish,
+          ifnull(round(sum(cost) / sum(install_finish),3),0) install_finish_cost,
+          ifnull(round(sum(install_finish) / sum(download_finish) * 100,3),0) install_finish_rate,
+          sum(active) active,
+          ifnull(round(sum(cost) / sum(active), 3),0) active_cost,
+          ifnull(round(sum(active) / sum(click) * 100,3),0) active_rate,
+          sum(register) register,
+          ifnull(round(sum(cost) / sum(register), 3),0) active_register_cost,
+          ifnull(round(sum(active_register_rate) /{day_count} * 100,3),0) active_register_rate,
+          sum(active_pay_amount) active_pay_amount,
+          sum(next_day_open) next_day_open,
+          ifnull(round(sum(cost) / sum(next_day_open),3),0) next_day_open_cost,
+          ifnull(round(sum(next_day_open) / sum(active) * 100,3),0) next_day_open_rate,
+          sum(attribution_next_day_open_cnt) attribution_next_day_open_cnt,
+          ifnull(round(sum(cost) / sum(	attribution_next_day_open_cnt),3),0) attribution_next_day_open_cost,
+          ifnull(round(sum(	attribution_next_day_open_cnt) / sum(active) * 100,3),0) attribution_next_day_open_rate,
+          sum(game_addiction) game_addiction,
+          ifnull(round(sum(cost) / sum(game_addiction),3),0) game_addiction_cost,
+          ifnull(round(sum(game_addiction_rate) /{day_count} * 100,3),0) game_addiction_rate,
+          sum(pay_count) pay_count,
+          ifnull(round(sum(cost) / sum(pay_count), 3),0) active_pay_cost,
+          ifnull(round(sum(pay_count) / sum(active) * 100,3),0) active_pay_rate,
+          sum(loan_completion) loan_completion,
+          ifnull(round(sum(cost) / sum(loan_completion),3),0) loan_completion_cost,
+          ifnull(round(sum(loan_completion) / sum(register) * 100,3),0) loan_completion_rate,
+          ifnull(round(sum(pre_loan_credit), 3),0) pre_loan_credit,
+          ifnull(round(sum(cost) / sum(pre_loan_credit),3),0) pre_loan_credit_cost,
+          sum(loan_credit) loan_credit,
+          ifnull(round(sum(cost) / sum(loan_credit),3),0) loan_credit_cost,
+          ifnull(round(sum(loan_credit) / sum(loan_completion) * 100,3),0) loan_credit_rate,
+          sum(in_app_uv) in_app_uv,
+          sum(in_app_detail_uv) in_app_detail_uv,
+          sum(in_app_cart) in_app_cart,
+          sum(in_app_pay) in_app_pay,
+          sum(in_app_order) in_app_order,
+          ifnull(round(sum(	attribution_game_pay_7d_count) /{day_count}, 3),0) attribution_game_pay_7d_count,
+          ifnull(round(sum(	attribution_game_pay_7d_cost) /{day_count}, 3),0) attribution_game_pay_7d_cost,
+          ifnull(round(sum(	attribution_active_pay_7d_per_count) /{day_count}, 3),0) attribution_active_pay_7d_per_count,
+          sum(game_pay_cost) game_pay_cost,
+          sum(game_pay_count) game_pay_count,
+          sum(phone) phone,
+          sum(form) form,
+          sum(map_search) map_search,
+          sum(button) button,
+          sum(`view`) `view`,
+          sum(download) download,
+          sum(qq) qq,
+          sum(lottery) lottery,
+          sum(vote) vote,
+          sum(message) message,
+          sum(redirect) redirect,
+          sum(shopping) shopping,
+          sum(consult) consult,
+          sum(wechat) wechat,
+          sum(phone_confirm) phone_confirm,
+          sum(phone_connect) phone_connect,
+          sum(consult_effective) consult_effective,
+          sum(coupon) coupon,
+          sum(coupon_single_page) coupon_single_page,
+          sum(redirect_to_shop) redirect_to_shop,
+          sum(poi_collect) poi_collect,
+          sum(poi_address_click) poi_address_click,
+          sum(luban_order_cnt) luban_order_cnt,
+          sum(luban_order_stat_amount) luban_order_stat_amount,
+          sum(luban_order_roi) luban_order_roi,
+          sum(luban_live_enter_cnt) luban_live_enter_cnt,
+          sum(live_watch_one_minute_count) live_watch_one_minute_count,
+          sum(luban_live_follow_cnt) luban_live_follow_cnt,
+          sum(live_fans_club_join_cnt) live_fans_club_join_cnt,
+          sum(luban_live_comment_cnt) luban_live_comment_cnt,
+          sum(luban_live_share_cnt) luban_live_share_cnt,
+          sum(luban_live_gift_cnt) luban_live_gift_cnt,
+          sum(luban_live_gift_amount) luban_live_gift_amount,
+          sum(luban_live_slidecart_click_cnt) luban_live_slidecart_click_cnt,
+          sum(luban_live_click_product_cnt) luban_live_click_product_cnt,
+          sum(luban_live_pay_order_count) luban_live_pay_order_count,
+          sum(luban_live_pay_order_stat_cost) luban_live_pay_order_stat_cost,
+          sum(wechat_login_count) wechat_login_count,
+          sum(attribution_wechat_login_30d_count) attribution_wechat_login_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_login_count),3),0) wechat_login_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_login_30d_count),3),0) attribution_wechat_login_30d_cost,
+          sum(wechat_first_pay_count) wechat_first_pay_count,
+          sum(attribution_wechat_first_pay_30d_count) attribution_wechat_first_pay_30d_count,
+          ifnull(round(sum(cost) / sum(wechat_first_pay_count),3),0) wechat_first_pay_cost,
+          ifnull(round(sum(cost) / sum(	attribution_wechat_first_pay_30d_count),3),0) attribution_wechat_first_pay_30d_cost,
+          ifnull(round(sum(wechat_first_pay_count) / sum(wechat_login_count) * 100,3),0) wechat_first_pay_rate,
+          ifnull(round(sum(	attribution_wechat_first_pay_30d_count) / sum(	attribution_wechat_login_30d_count) * 100,3),0) attribution_wechat_first_pay_30d_rate,
+          sum(wechat_pay_amount) wechat_pay_amount,
+          sum(attribution_wechat_pay_30d_amount) attribution_wechat_pay_30d_amount,
+          sum(attribution_wechat_pay_30d_roi) attribution_wechat_pay_30d_roi,
+          sum(phone_effective) phone_effective,
+          sum(total_play) total_play,
+          sum(valid_play) valid_play,
+          ifnull(round(sum(cost) / sum(valid_play),3),0) valid_play_cost,
+          ifnull(round(sum(valid_play) / sum(`show`) * 100,3),0) valid_play_rate,
+          sum(play_25_feed_break) play_25_feed_break,
+          sum(play_50_feed_break) play_50_feed_break,
+          sum(play_75_feed_break) play_75_feed_break,
+          sum(play_100_feed_break) play_100_feed_break,
+          ifnull(round(sum(average_play_time_per_play) /{day_count}, 3),0) average_play_time_per_play,
+          ifnull(round(sum(play_over_rate) /{day_count} * 100,3),0) play_over_rate,
+          ifnull(round(sum(wifi_play) / sum(total_play) * 100,3),0) wifi_play_rate,
+          sum(wifi_play) wifi_play,
+          ifnull(round(sum(play_duration_sum) /{day_count}, 3),0) play_duration_sum,
+          sum(advanced_creative_phone_click) advanced_creative_phone_click,
+          sum(advanced_creative_counsel_click) advanced_creative_counsel_click,
+          sum(advanced_creative_form_click) advanced_creative_form_click,
+          sum(advanced_creative_coupon_addition) advanced_creative_coupon_addition,
+          sum(advanced_creative_form_submit) advanced_creative_form_submit,
+          sum(card_show) card_show,
+          sum(`share`) `share`,
+          sum(`comment`) `comment`,
+          sum(`like`) `like`,
+          sum(follow) follow,
+          sum(home_visited) home_visited,
+          sum(ies_challenge_click) ies_challenge_click,
+          sum(ies_music_click) ies_music_click,
+          sum(location_click) location_click,
+          sum(message_action) message_action,
+          sum(click_landing_page) click_landing_page,
+          sum(click_shopwindow) click_shopwindow,
+          sum(click_website) click_website,
+          sum(click_download) click_download,
+          sum(click_call_dy) click_call_dy,
+          sum(cpc) cpc,
+          sum(cpm) cpm,
+          sum(cpa) cpa,
+          ifnull(round(sum(interact_per_cost) /{day_count}, 3),0) interact_per_cost,
+          ifnull(round(sum(convert_show_rate) /{day_count}, 3),0) convert_show_rate,
+          ifnull(round(sum(play_duration_10s) / sum(total_play) * 100,3),0) play_duration_10s_rate,
+          ifnull(round(sum(play_50_feed_break) / sum(total_play) * 100,3),0) play_50_feed_break_rate,
+          ifnull(round(sum(play_25_feed_break) / sum(total_play) * 100,3),0) play_25_feed_break_rate,
+          ifnull(round(sum(play_duration_5s_rate) /{day_count}, 3),0) play_duration_5s_rate,
+          ifnull(round(sum(play_duration_2s) / sum(total_play) * 100,3),0) play_duration_2s_rate,
+          ifnull(round(sum(average_play_progress) /{day_count}, 3),0) average_play_progress,
+          ifnull(round(sum(play_100_feed_break) / sum(total_play) * 100,3),0) play_100_feed_break_rate,
+          ifnull(round(sum(play_duration_3s) / sum(total_play) * 100,3),0) play_duration_3s_rate,
+          ifnull(round(sum(play_75_feed_break) / sum(total_play) * 100,3),0) play_75_feed_break_rate,
+          sum(play_duration) play_duration,
+          sum(play_duration_3s) play_duration_3s,
+          sum(play_duration_2s) play_duration_2s,
+          sum(play_duration_10s) play_duration_10s,
+          ifnull(round(sum(average_video_play) /{day_count}, 3),0) average_video_play,
+          sum(avg_rank) avg_rank,
+          sum(submit_certification_count) submit_certification_count,
+          sum(approval_count) approval_count,
+          sum(first_order_count) first_rental_order_count,
+          sum(first_rental_order_count) first_order_count,
+          sum(commute_first_pay_count) commute_first_pay_count
          FROM media_api.bytedance_material_report_daily zhubiao
          WHERE image_mode IN (
                               'CREATIVE_IMAGE_MODE_VIDEO',
@@ -657,7 +461,8 @@ FROM (
                     from `media_api`.bytedance_file_video_get where advertiser_id={account_id}
                     group by advertiser_id, signature, material_id, filename, video_url) video
                    ON report.account_id = video.advertiser_id AND report.material_id = video.material_id
-         LEFT JOIN `jeecg-boot`.ctop_material_info cmi ON video.signature = cmi.code
+         LEFT JOIN (select  code,material_name from `jeecg-boot`.ctop_material_info where status=1) cmi 
+          ON video.signature = cmi.code
          LEFT JOIN (select material_id, clip_id, shot_id, plan_id, leader_id
                     from (
                              select material_id,