ahmedrahil786

1 to 5 reservations vs count of Members - Rahil

Jan 24th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. select
  2. count(distinct case when A.resv > 0 then A.mid end) as 1_res,
  3. count(distinct case when A.resv > 1 then A.mid end) as 2_res,
  4. count(distinct case when A.resv > 2 then A.mid end) as 3_res,
  5. count(distinct case when A.resv > 3 then A.mid end) as 4_res,
  6. count(distinct case when A.resv > 4 then A.mid end) as 5_res
  7. from
  8. (select
  9. distinct r.member_id as mid, count(r.id) as resv
  10. from reservations r left join members m on m.id = r.member_id
  11. where r.state = 'completed'
  12. and m.imaginary in ('sofam', 'normal')
  13. and r.member_id not in ('125', '127')
  14. group by 1) A
  15. where A.resv > 0
Advertisement
Add Comment
Please, Sign In to add comment