ahmedrahil786

Signups to MFT - % of Conversion Ratio - Rahil

Jan 20th, 2020
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. set @startdate1 = '2019-09-01';
  2. set @startdate2 = '2020-12-01';
  3. Select P.week , Count(distinct P.mid) as MFTs , sum( Q.resv) as resv , sum(Q.gross_rev) as Gross, Sum(Q.coupon_spent) as coupon_spent, Sum(Q.net_rev) as net_rev,
  4. ROUND(Sum(Q.net_rev)/sum( Q.resv),2) as Net_spent_per_resv, Round(sum( Q.resv) / Count(P.mid),2) as Resv_MFT_Ratio
  5. from
  6. (Select I.mid as mid, Weekofyear(I.return_date) as week
  7. from
  8. (select A.return_date as return_date, A.rid2 as rid,A.mid as mid, A.dur as dur, A.policy_id,
  9. A.codes as codes, if(rid2=firstRes,1,0) as mft from
  10. (select
  11. distinct r.id as rid2, r.member_id as mid, c.code as codes,c.coupon_policy_id as policy_id,
  12. ifnull((select min(id) from reservations where state='completed' and r.member_id=member_id group by member_id),0) as firstRes,
  13. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  14. Date(r.return_at + interval '8' hour) as return_Date
  15. from reservations r left join members m on r.member_id = m.id
  16. left join coupons c on c.reservation_id = r.id
  17. where r.state in ('completed','inUse','reserved')
  18. and r.return_at + interval 8 hour >= @startdate1
  19. and r.return_at + interval 8 hour <= @startdate2
  20. and m.imaginary in ('sofam', 'normal')
  21. and r.member_id not in ('125', '127')
  22. group by rid2) A
  23. group by 2
  24. order by 1 asc) I
  25. Where I.mft = 1
  26. group by 1 ) P
  27. left join
  28. (select distinct A.mid, count(A.rid2) as resv, weekofyear(A.date) as week, sum(IFNULL(E.charges,0)) as gross_rev,
  29. sum(IFNULL(F.coupon_Spent,0)) as Coupon_Spent,
  30. sum(round((IFNULL(E.charges,0) - IFNULL(F.coupon_Spent,0)),2)) as net_rev from
  31. (select
  32. distinct r.id as rid2, r.member_id as mid,
  33. date(r.return_at + interval '8' hour) as date
  34. from reservations r left join members m on r.member_id = m.id
  35. where r.state in ('completed','inUse','reserved')
  36. and r.return_at + interval 8 hour >= @startdate1
  37. and r.return_at + interval 8 hour <= @startdate2
  38. and m.imaginary in ('sofam', 'normal')
  39. and r.member_id not in ('125', '127')) A
  40. left join
  41. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  42. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage','insurance')
  43. group by rid) E on A.rid2 = E.rid
  44. left join
  45. (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
  46. where p.state = 'normal' and p.paid_type = 'coupon'
  47. group by p.reservation_id) F on A.rid2 = F.rid
  48. group by 1,3
  49. order by 3 asc , 1 asc) Q
  50. on P.mid = Q.mid and P.week = Q.week
  51. group by 1
Advertisement
Add Comment
Please, Sign In to add comment