dm_pitcher_daily_overview.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. """
  2. @desc 投手累计数据
  3. @auth ck
  4. """
  5. from model.DateUtils import DateUtils
  6. from model.DataBaseUtils import MysqlUtils,CkUtils
  7. du = DateUtils()
  8. db= MysqlUtils()
  9. ck = CkUtils()
  10. def dm_pitcher_daily_overview():
  11. sql=f"""
  12. select
  13. q.pitcher,
  14. channel_count,
  15. on_channel_count,
  16. channel_count-on_channel_count off_channel_count,
  17. this_month_cost,
  18. this_month_amount,
  19. if(this_month_cost = 0, 0, round(this_month_amount / this_month_cost, 4)) this_month_roi,
  20. last_month_cost,
  21. last_month_amount,
  22. if(last_month_cost = 0, 0, last_month_amount / last_month_cost) last_month_roi,
  23. last_month_far_amount,
  24. follow_user,
  25. if(last_month_cost = 0, 0, last_month_far_amount / last_month_cost) last_month_far_roi
  26. from (select pitcher,
  27. sum(follow_user) follow_user
  28. from dw_daily_channel
  29. group by pitcher) q
  30. left outer join
  31. (select count(distinct channel) channel_count, pitcher
  32. from dw_daily_channel_cost
  33. where dt = '{du.get_n_days(0)}'
  34. group by pitcher) w
  35. on q.pitcher = w.pitcher
  36. left outer join(
  37. select count(distinct channel) on_channel_count, pitcher
  38. from dw_daily_channel_cost
  39. where dt >= '{du.get_n_days(-15)}'
  40. and cost > 0
  41. group by pitcher) e
  42. on q.pitcher = e.pitcher
  43. left outer join (
  44. select pitcher,
  45. sum(cost) this_month_cost
  46. from dw_daily_channel
  47. where dt >= '{du.get_n_pre_month_first_day(0)}'
  48. group by pitcher) r
  49. on q.pitcher = r.pitcher
  50. left outer join(
  51. select pitcher,
  52. sum(cost) last_month_cost
  53. from dw_daily_channel
  54. where dt >= '{du.get_n_pre_month_first_day(1)}'
  55. and dt < '{du.get_n_pre_month_first_day(0)}'
  56. group by pitcher) t on q.pitcher = t.pitcher
  57. left outer join (
  58. select b.pitcher, sum(amount) last_month_far_amount
  59. from order a
  60. left outer join dw_daily_channel_cost b on a.channel = b.channel and a.date = b.dt
  61. where reg_time >= '{du.get_n_pre_month_first_day(1)} 00:00:00' and reg_time<'{du.get_n_pre_month_first_day(0)} 00:00:00'
  62. group by pitcher
  63. ) y on q.pitcher = y.pitcher
  64. left outer join (
  65. select b.pitcher, sum(amount) last_month_amount
  66. from order a
  67. left outer join dw_daily_channel_cost b on a.channel = b.channel and a.date = b.dt
  68. where reg_time >= '{du.get_n_pre_month_first_day(1)} 00:00:00' and reg_time<'{du.get_n_pre_month_first_day(0)} 00:00:00'
  69. and dt<'{du.get_n_pre_month_first_day(0)}'
  70. group by pitcher
  71. ) p on q.pitcher=p.pitcher
  72. left outer join (
  73. select b.pitcher, sum(amount) this_month_amount
  74. from order a
  75. left outer join dw_daily_channel_cost b on a.channel = b.channel and a.date = b.dt
  76. where reg_time >= '{du.get_n_pre_month_first_day(0)} 00:00:00'
  77. group by pitcher
  78. ) g on q.pitcher=g.pitcher
  79. """
  80. data=ck.execute(sql)
  81. # print(data)
  82. db.quchen_text.executeMany("replace into dm_pitcher_daily_overview values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",data)
  83. if __name__ == '__main__':
  84. dm_pitcher_daily_overview()