ahmedrahil786

MFTs by City - Rahil - Count by Week and Month

Jun 17th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 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.city,"") as City
  7. from
  8. (select
  9. distinct c.member_id as mid,
  10. WEEKOFYEAR(c.created_at + interval '8' hour) as Week
  11. from charges c
  12. where c.kind = 'subscriptionFee'
  13. and c.created_at + interval '8' hour >= @start) A
  14. left join
  15. (select
  16. distinct r.member_id as mid,
  17. min(r.id) as rid,
  18. z.city as city
  19. from reservations r
  20. join members m on r.member_id = m.id
  21. join zones z on r.start_zone_id = z.id
  22. where m.imaginary in ('sofam', 'normal')
  23. and r.member_id not in ('125', '127')
  24. and r.start_at + interval '8' hour >= @start
  25. group by r.member_id) B
  26. on A.mid = B.mid
  27. where B.city is not null
  28. group by A.week,city ;
  29.  
  30. set @start := '2019-1-1';
  31. select
  32. A.month,
  33. count(A.mid) as totalmfts,
  34. IFNULL(B.city,"") as City
  35. from
  36. (select
  37. distinct c.member_id as mid,
  38. Month(c.created_at + interval '8' hour) as month
  39. from charges c
  40. where c.kind = 'subscriptionFee'
  41. and c.created_at + interval '8' hour >= @start) A
  42. left join
  43. (select
  44. distinct r.member_id as mid,
  45. min(r.id) as rid,
  46. z.city as city
  47. from reservations r
  48. join members m on r.member_id = m.id
  49. join zones z on r.start_zone_id = z.id
  50. where m.imaginary in ('sofam', 'normal')
  51. and r.member_id not in ('125', '127')
  52. and r.start_at + interval '8' hour >= @start
  53. group by r.member_id) B
  54. on A.mid = B.mid
  55. where B.city is not null
  56. group by A.month,city
Advertisement
Add Comment
Please, Sign In to add comment