ahmedrahil786

Member Retention , Revisit - 30 days - Rahil

Mar 9th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. Select Distinct L.mid as mid,L.name as name, L.MFT_date as MFT_date, L.coupon as coupon, L.age as age, count(L.rid) as rid, sum(L.dur) as Dur , Round(Avg(L.dur),2) as Dur,
  2. Round(Sum(L.gross_rev),02) as Gross_rev, Round(Sum(L.net_rev),2) as net_rev, round(Avg(L.net_rev),2) as net_rev from
  3. (select A.mid as mid,A.name as name, A.rid as rid,(A.age) as age, A.dur as dur,IFNULL(E.charges,0) as gross_rev, B.coupon as coupon,
  4. IFNULL(F.coupon_Spent,0) as Coupon_Spent, round((IFNULL(E.charges,0) - IFNULL(F.coupon_Spent,0)),2) as net_rev, B.date as MFT_date, A.date as Resv_date1, A.date - B.date as diff from
  5. (select r.id as rid, r.member_id as mid,m.display_name as name, Date(r.start_at + interval 8 hour) as Date, round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,(YEAR(r.start_at) - YEAR(m.birthday)) as age
  6. from reservations r left join members m on m.id = r.member_id
  7. where r.state = 'completed'
  8. and m.imaginary in ('sofam', 'normal')
  9. and r.member_id not in ('125', '127')
  10. group by 1) A
  11. left join
  12. ################## To find the first Booking
  13. (select distinct r.member_id as mid, min(r.id) as mrid, IFNULL(co.comment,"") as coupon,
  14. date(r.return_at + interval 8 hour) as date
  15. from reservations r left join members m on m.id = r.member_id
  16. left join coupons co on co.reservation_id = r.id
  17. where r.state = 'completed'
  18. and m.imaginary in ('sofam', 'normal')
  19. and r.member_id not in ('125', '127')
  20. group by 1) B
  21. on A.mid = B.mid
  22. ############## Total spent
  23. left join
  24. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  25. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage')
  26. group by rid) E on A.rid = E.rid
  27. left join
  28. (select p.reservation_id as rid, month(p.created_at + interval '8' hour) as month,Year(p.created_at + interval '8' hour) as year, IFNULL(p.amount,0) as coupon_Spent from payments p
  29. where p.state = 'normal' and p.paid_type = 'coupon'
  30. group by p.reservation_id) F on A.rid = F.rid
  31. order by 1,2 asc) L
  32. where L.diff < 30
  33. group by 1 ;
Advertisement
Add Comment
Please, Sign In to add comment