drop table if exists shjy.overview;
create view shjy.overview as
(
select date,
       `#os`,
       `#bundle_id`,
       owner_name,
       channel,
       active_num,
       new_account_num,
       pay_account_num,
       money,
       new_account_recharge.accout_num           as new_pay_account_num,
       new_account_recharge.money                as new_money
--        round(pay_account_num / active_num, 2)    as pay_rate,
--        round(money / pay_account_num, 2)         as arppu,
--        round(money / active_num, 2)              as arpu,
--        round(new_money / new_pay_account_num, 2) as new_arppu,
--        round(new_money / new_account_num, 2)     as new_arpu

from (select date,
             `#os`,
             `#bundle_id`,
             owner_name,
             channel,
             active_num,
             new_account_num,
             account_num as pay_account_num,
             money
      from (select date,
                   `#os`,
                   `#bundle_id`,
                   owner_name,
                   channel,
                   num             as active_num,
                   new_account.num as new_account_num
            from shjy.active_account
                     left join shjy.new_account
                               on
                                       active_account.date = new_account.date and
                                       active_account.`#bundle_id` = new_account.`#bundle_id` and
                                       active_account.`#os` = new_account.`#os` and
                                       active_account.owner_name = new_account.owner_name and
                                       active_account.channel = new_account.channel) as tb1
               left join shjy.recharge_game on
              tb1.date = recharge_game.date and
              tb1.`#bundle_id` = recharge_game.`#bundle_id` and
              tb1.`#os` = recharge_game.`#os` and
              tb1.owner_name = recharge_game.owner_name and
              tb1.channel = recharge_game.channel) as tb2
         left join shjy.new_account_recharge on tb2.date = new_account_recharge.date and
                                           tb2.`#bundle_id` = new_account_recharge.`#bundle_id` and
                                           tb2.`#os` = new_account_recharge.`#os` and
                                           tb2.owner_name = new_account_recharge.owner_name and
                                           tb2.channel = new_account_recharge.channel)