ahmedrahil786

Apo - Loyalty - last year coupon

Aug 27th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. set @yearmonth = 201908;
  2.  
  3. select m.id, m.first_name, m.last_name, m.email, ma.phone,
  4. sum(timestampdiff(minute,r.occupy_start_at,r.occupy_end_at)) as total_minutes_booked,
  5. count(distinct r.id) as bookings
  6. from members m
  7. join member_appendixes ma on ma.member_id = m.id
  8. join reservations r on r.member_id = m.id
  9. where r.state IN ('completed','returnDelayed')
  10. and m.imaginary NOT IN ('wash','commonBlock','accident','d2dAgent','test')
  11. and extract(year_month from r.occupy_start_at) = @yearmonth
  12. group by 1, ma.phone
Advertisement
Add Comment
Please, Sign In to add comment