ahmedrahil786

Memebers with Reservations - Query for Push Notification

May 8th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. select
  2.  
  3. *
  4. from
  5.  
  6. (select
  7. distinct m.id as mid,
  8. m.email
  9. from members m
  10. where m.state = 'normal'
  11. and m.imaginary = 'normal'
  12. and m.email not like '%%@socar.my'
  13. and CONVERT_TZ(m.created_at, '+00:00', '+8:00') >= '2019-1-1 00:00') A
  14.  
  15. left join
  16.  
  17. (select
  18. r.id as rid,
  19. r.member_id as mid,
  20. Date(CONVERT_TZ(r.start_at, '+00:00', '+8:00')) as date
  21. from reservations r
  22. where CONVERT_TZ(r.start_at, '+00:00', '+8:00') >= '2019-1-1 00:00'
  23. and r.state = 'completed') B
  24.  
  25. on A.mid = B.mid
  26.  
  27.  
  28.  
  29. order by B.date;
  30.  
  31. ########################Updated Query
  32.  
  33. select
  34. m.id as mid,
  35. m.email as email,
  36. m.display_name as displayname,
  37. m.first_name as firstname,
  38. date(m.created_at + interval '8' hour) as date,
  39. IFNULL((select distinct r.member_id from reservations r where r.state = 'completed' and r.member_id = m.id),0) as matchedmid
  40. from members m
  41. Where m.imaginary = 'normal'
  42. and m.state = 'normal'
  43. and m.email not like '%%@socar.my';
Advertisement
Add Comment
Please, Sign In to add comment