ahmedrahil786

MFTs by week and Month and zone

Jun 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. set @start := '2019-1-1';
  2.  
  3. select
  4. A.week,
  5. count(A.mid) as totalmfts,
  6. IFNULL(B.Region,"") as Region,
  7. IFNULL(B.zid,"") as zid,
  8. IFNULL(B.name,"") as name
  9. from
  10. (select
  11. distinct c.member_id as mid,
  12. WEEKOFYEAR(c.created_at + interval '8' hour) as Week
  13. from charges c
  14. where c.kind = 'subscriptionFee'
  15. and c.created_at + interval '8' hour >= @start) A
  16. left join
  17. (select
  18. distinct r.member_id as mid,
  19. min(r.id) as rid,
  20. z.region as Region,
  21. z.id as zid,
  22. z.name as name
  23. from reservations r
  24. join members m on r.member_id = m.id
  25. join zones z on r.start_zone_id = z.id
  26. where m.imaginary in ('sofam', 'normal')
  27. and r.member_id not in ('125', '127')
  28. and r.start_at + interval '8' hour >= @start
  29. group by r.member_id) B
  30. on A.mid = B.mid
  31. where B.Region is not null
  32. group by A.week,Region,B.zid ;
Advertisement
Add Comment
Please, Sign In to add comment