ahmedrahil786

Coupon Active Bookings - Leon

Jun 3rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. select
  2. cp.name,
  3. count(distinct c.member_id) as applies,
  4. count(distinct c.reservation_id) as bookings,
  5. count(distinct r.member_id) as ActiveMembers
  6.  
  7. from coupons c
  8.  
  9. left outer join reservations r
  10. on r.id = c.reservation_id
  11.  
  12. join members m
  13. on m.id = c.member_id and m.imaginary = 'normal'
  14.  
  15. join coupon_policies cp
  16. on c.coupon_policy_id = cp.id
  17.  
  18. where c.coupon_policy_id IN (655, 656)
  19. #and c.member_id IN (select ch.member_id from charges ch where ch.kind = 'subscriptionFee' and ch.created_at + interval '8' hour >= '2019-5-14')
  20. #and r.member_id IN (select ch.member_id from charges ch where ch.kind = 'subscriptionFee' and ch.created_at + interval '8' hour >= '2019-5-14')
  21.  
  22. group by 1;
Add Comment
Please, Sign In to add comment