ahmedrahil786

Retention chart - With coupon Vs Non Coupon Bookings

Dec 2nd, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. select
  2. A.memberid as memberid,
  3. A.MFT_rid,
  4. IFnull(B.coupon,0) as coupon_used,
  5. Date(A.MFTDate) as MFTdate,
  6. date(A.lastactivedate) as lastactivedate
  7. from
  8. (select
  9. distinct m.id as memberid,
  10. min(r.id) as MFT_rid,
  11. min(r.return_at + interval 8 hour) as MFTdate,
  12. Max(r.return_at + interval 8 hour ) as lastactivedate
  13. from members m
  14. left join reservations r on m.id = r.member_id
  15. Where r.id != 0
  16. and m.imaginary in ('sofam', 'normal')
  17. and r.state = 'completed'
  18. group by m.id) A
  19. left join
  20. (select
  21. r.id as rid,
  22. c.comment as coupon
  23. from reservations r
  24. left outer join coupons c on c.reservation_id = r.id
  25. group by r.id) B
  26. on A.MFT_rid = B.rid
Advertisement
Add Comment
Please, Sign In to add comment