ahmedrahil786

SMM Sprint Tracker for Jason - Rahil

Aug 28th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. set @start := '2019-1-1';
  2. Select P.month, P.GrabMFT,P.TotalMFTs, Round((P.GrabMFT/P.TotalMFTs)*100,2) as Grabpay_MFT_PCT_Total,ROUND(P.GrabPay,2) as Grabpay_Rev,Round(ROUND(P.GrabPay,2)/ROUND(P.NetRev,2)*100,2) as Grabpay_rev_PCT_Total_NetRev,
  3. Q.MFT_Oneway,R.MFT_PCT_DIFF as MFT_PCT_DIFF
  4. #P.mft_21, ROUND(P.NetRev,2) as Net_rev, ROUND(P.GrossRev,2) as Gross_rev,R.Diff_MFT_Oneway_MOM as Diff_MFT_Oneway_MOM
  5. from
  6. (select
  7. A.month as month,A.TotalMFTs as TotalMFTs,A.GrabMFT as GrabMFT,A.mft_21 as mft_21,IFNULL(B.NetRev,0) as NetRev,IFNULL(B.GrabPay,0) as GrabPay,B.GrossRev as GrossRev
  8. from (select
  9. Month(c.created_at + interval '8' hour) as month,
  10. count(distinct case when c.kind = 'subscriptionFee' and str_to_date(m.birthday, '%Y%m%d') >= NOW() - interval '21' year then c.member_id end) as mft_21,
  11. count(distinct case when c.kind = 'subscriptionFee' and pm.card_type = 'eWallet' and (c.created_at + interval '8' hour) >= '2019-6-12' then c.member_id end) as GrabMFT,
  12. count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as TotalMFTs
  13. from charges c join members m on m.id = c.member_id
  14. join payment_methods pm on pm.member_id = m.id
  15. left outer join member_appendixes ma on ma.id = m.id
  16. where c.created_at + interval '8' hour >= @start
  17. and m.imaginary = 'normal'
  18. group by 1) A
  19. join (
  20. select
  21. month(r.created_at + interval '8' hour) as month,
  22. sum(case when p.state = 'normal' and p.paid_type IN ('card', 'eWallet') then p.amount end) as NetRev,
  23. sum(case when p.state = 'normal' and p.paid_type IN ('eWallet') and (r.start_at + interval '8' hour) >= '2019-6-12' then p.amount end) as GrabPay,
  24. sum(case when p.state = 'normal' then p.amount end) as GrossRev
  25. from reservations r
  26. join members m on m.id = r.member_id and m.email not like '%socar.my%' and m.imaginary = 'normal'
  27. join payments p on p.reservation_id = r.id
  28. where r.created_at + interval '8' hour >= @start and p.state = 'normal'
  29. group by 1 order by 1 asc) B
  30. on B.month = A.month group by 1 order by 1 asc) P
  31. join
  32. (Select month(A.date) as month, Count(A.rid) as MFT_Oneway from
  33. (select FB.rid2 as rid, FB.mid as mid, FB.way as way, FB.date as date from
  34. (select r.id as rid2 ,r.start_zone_id as stid, r.end_zone_id as edid,
  35. date(r.start_at + interval '8' hour) as date,
  36. fbo.mid as mid,fbo.rid,fbo.way as way from
  37. reservations r
  38. join
  39. (select
  40. fbi.mid as mid,fbi.rid as rid,fbi.way as way from
  41. (select
  42. distinct r.member_id as mid, min(r.id) as rid, r.way as way
  43. from reservations r join members m on m.id = r.member_id
  44. where r.state = 'completed' and m.imaginary = 'normal' and m.email not like '%socar.my%' group by r.member_id) fbi
  45. where fbi.way in ('oneway','onewayReturn') ) fbo on fbo.rid = r.id
  46. where r.start_zone_id in ('244','245') or r.end_zone_id in ('244','245') )FB
  47. where date(FB.date + interval '8' hour) >= '2019-01-01') A group by month order by month desc ) Q
  48. on P.month = Q.month
  49. left join
  50. (Select
  51. t1.month as month,
  52. t1.MFT_Oneway as MFT_Oneway,
  53. t1.MFT_Oneway - COALESCE(t2.MFT_Oneway, t1.MFT_Oneway) AS Diff_MFT_Oneway_MOM,
  54. IFNULL(Round(((t1.MFT_Oneway - COALESCE(t2.MFT_Oneway, t1.MFT_Oneway))/t2.MFT_Oneway)*100,2),"") as MFT_PCT_DIFF
  55. from
  56.  
  57. (Select month(A.date) as month, Count(A.rid) as MFT_Oneway from
  58. (select FB.rid2 as rid, FB.mid as mid, FB.way as way, FB.date as date from
  59. (select r.id as rid2 ,r.start_zone_id as stid, r.end_zone_id as edid,
  60. date(r.start_at + interval '8' hour) as date,
  61. fbo.mid as mid,fbo.rid,fbo.way as way from
  62. reservations r
  63. join
  64. (select
  65. fbi.mid as mid,fbi.rid as rid,fbi.way as way from
  66. (select
  67. distinct r.member_id as mid, min(r.id) as rid, r.way as way
  68. from reservations r join members m on m.id = r.member_id
  69. where r.state = 'completed' and m.imaginary = 'normal' and m.email not like '%socar.my%' group by r.member_id) fbi
  70. where fbi.way in ('oneway','onewayReturn') ) fbo on fbo.rid = r.id
  71. where r.start_zone_id in ('244','245') or r.end_zone_id in ('244','245') )FB
  72. where date(FB.date + interval '8' hour) >= '2019-01-01') A group by month order by month desc ) t1
  73.  
  74. left join
  75. #Month(date_add(czl.log_date , interval 1 month)) as date,
  76. (Select month(date_add(A.date, interval 1 month)) as month, Count(A.rid) as MFT_Oneway from
  77. (select FB.rid2 as rid, FB.mid as mid, FB.way as way, FB.date as date from
  78. (select r.id as rid2 ,r.start_zone_id as stid, r.end_zone_id as edid,
  79. date(r.start_at + interval '8' hour) as date,
  80. fbo.mid as mid,fbo.rid,fbo.way as way from
  81. reservations r
  82. join
  83. (select
  84. fbi.mid as mid,fbi.rid as rid,fbi.way as way from
  85. (select
  86. distinct r.member_id as mid, min(r.id) as rid, r.way as way
  87. from reservations r join members m on m.id = r.member_id
  88. where r.state = 'completed' and m.imaginary = 'normal' and m.email not like '%socar.my%' group by r.member_id) fbi
  89. where fbi.way in ('oneway','onewayReturn') ) fbo on fbo.rid = r.id
  90. where r.start_zone_id in ('244','245') or r.end_zone_id in ('244','245') )FB
  91. where date(FB.date + interval '8' hour) >= '2019-01-01') A group by month order by month desc ) t2
  92. on t1.month = t2.month
  93. order by t1.month desc) R
  94. on R.month = P.month
  95. where P.month >= Month(now() - Interval 2 month)
Advertisement
Add Comment
Please, Sign In to add comment