ahmedrahil786

One way trip - Retention Cohort - Time Diff BTW Reser - 29/7

Jul 29th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. set @startdate1 = '2019-01-01';
  2. select
  3. B.mid as memberid,A.age as age,P.rid as rid, P.way as way, P.zone_name,P.reservationdate as res_date,Date(A.MFTDate) as MFTdate,date(A.lastactivedate) as lastactivedate
  4. from
  5. (select
  6. m.id as mid,
  7. r.id as rid,
  8. r.way as way,
  9. z.name as zone_name,
  10. Date(r.start_at + interval '8' hour) as reservationdate
  11. from members m
  12. left outer join reservations r on m.id = r.member_id
  13. join zones z on r.start_zone_id = z.id
  14. Where r.start_at != 0
  15. and m.imaginary = 'normal'
  16. and r.state = 'completed'
  17. group by m.id,r.id) P
  18. left join
  19. (select FB.rid2 as rid, FB.mid, FB.way, FB.date from
  20. (select r.id as rid2 ,r.start_zone_id as stid, r.end_zone_id as edid,
  21. date(r.start_at + interval '8' hour) as date,
  22. fbo.mid as mid,fbo.rid,fbo.way as way from
  23. reservations r
  24. join
  25. (select
  26. fbi.mid as mid,fbi.rid as rid,fbi.way as way from
  27. (select
  28. distinct r.member_id as mid, min(r.id) as rid, r.way as way
  29. from reservations r join members m on m.id = r.member_id
  30. where r.state = 'completed' and m.imaginary = 'normal' and m.email not like '%socar.my%' group by r.member_id) fbi
  31. where fbi.way in ('oneway','onewayReturn') ) fbo on fbo.rid = r.id
  32. where r.start_zone_id in ('244','245') or r.end_zone_id in ('244','245') )FB
  33. where date(FB.date + interval '8' hour) >= @startdate1) B
  34. on P.mid = B.mid
  35. join
  36. (select
  37. m.id as mid,
  38. TIMESTAMPDIFF(YEAR, str_to_date(m.birthday, '%Y%m%d'), r.start_at) AS age,
  39. r.id as rid, min(r.start_at + interval 8 hour) as MFTdate,Max(r.start_at + interval 8 hour) as lastactivedate
  40. from members m
  41. left outer join reservations r on m.id = r.member_id
  42. join charges c on m.id = c.member_id
  43. Where r.start_at != 0 and m.imaginary = 'normal' and c.kind = 'subscriptionFee' and date(c.created_at + interval '8' hour) >= @startdate1
  44. group by m.id) A
  45. on A.mid = B.mid
Advertisement
Add Comment
Please, Sign In to add comment