ahmedrahil786

TTT - Host acquisition Queries - 90 days Inactive

Oct 25th, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #### One way
  2.  
  3. Select distinct r.member_id as mid, m.display_name as name, m.email as email from reservations r
  4. join members m on m.id = r.member_id
  5. where r.way in ('oneway','onewayReturn')
  6. and m.imaginary in ('normal')
  7. order by 1 desc;
  8.  
  9. #### last 90 Days inactive and only one reservation
  10.  
  11. select A.mid as mid , A.name as name ,A.email as email from
  12. (Select distinct r.member_id as mid, count(r.id) as reservations, max(Date(r.start_at + interval 8 hour)) as last_resv_date,
  13. m.display_name as name, m.email as email from reservations r
  14. join members m on m.id = r.member_id
  15. where r.state = 'completed'
  16. and m.imaginary in ('normal')
  17. group by 1 desc
  18. order by 1 desc) A
  19. where A.reservations = '1'
  20. and A.last_resv_date <= date_sub(CURDATE(), interval 90 day) ;
  21.  
  22. #### No Reservation but Docs + Payment Approved
  23.  
  24. select A.mid as mid, A.name as name, A.email as email from
  25. (select distinct m.id as mid , m.display_name as name, m.email as email,
  26. count(distinct case when dl.state = 'approved' then dl.member_id end) DocApproved,
  27. count(distinct case when pm.state = 'approved' then pm.member_id end) cardupload,
  28. count(r.id) as reservations,
  29. max(Date(r.start_at + interval 8 hour)) as last_resv_date
  30. from members m
  31. left join driver_licenses dl on dl.member_id = m.id
  32. left join payment_methods pm on pm.member_id = m.id
  33. left join reservations r on m.id = r.member_id
  34. where m.imaginary in ('normal')
  35. group by 1
  36. order by 1 desc ) A
  37. where A.reservations = 0
  38. and A.DocApproved = 1
  39. and A.cardupload = 1
  40. #and A.last_resv_date <= date_sub(CURDATE(), interval 90 day);
Advertisement
Add Comment
Please, Sign In to add comment