ahmedrahil786

W.O.W Completed MFT Query - Rahil

Sep 3rd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. set @start := '2019-1-1';
  2. Select L.week, Count(L.mid) as mid from
  3. (Select B.week as week, B.mid as mid from
  4. (select distinct c.member_id as mid, weekofyear(c.created_at + interval '8' hour) as week
  5. from charges c join members m on m.id = c.member_id
  6. where c.kind = 'subscriptionFee'
  7. and m.imaginary in ('normal','sofam')
  8. and date(c.created_at + interval '8' hour) >= @start) A
  9. join
  10. (Select Distinct r.member_id as mid, weekofyear(r.return_at + interval '8' hour) as week
  11. from reservations r join members m on m.id = r.member_id
  12. where m.imaginary in ('normal','sofam')
  13. and date(r.return_at + interval '8' hour) >= @start
  14. and r.state in ('completed','inUse', 'reserved')
  15. group by 1) B
  16. on B.mid = A.mid
  17. group by 2
  18. order by 1 desc) L
  19. Group by 1
  20. order by 1 desc
Add Comment
Please, Sign In to add comment