ahmedrahil786

F4 - W_member

May 18th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. set @start := '2019-1-1 00:00';
  2.  
  3. select
  4. D.date,
  5. D.TotalMFTs
  6.  
  7. from (select date(c.created_at + interval '8' hour) as date, count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as TotalMFTs from charges c
  8. join members m on m.id = c.member_id
  9. where c.created_at + interval '8' hour >= @start and m.imaginary = 'normal'
  10. group by 1) D
  11. group by 1
  12. order by 1 asc;
  13.  
  14. select
  15. A.month, A.AM, B.signups
  16. from
  17. (select
  18. month(r.occupy_start_at + interval '8' hour) as month,
  19. count(distinct case when r.state = 'completed' then r.member_id end) as AM
  20. from reservations r
  21. where r.start_at + interval '8' hour >= @start
  22. and r.state = 'completed'
  23. group by 1) A
  24.  
  25. left join
  26.  
  27. (select
  28. month(m.created_at + interval '8' hour) as month, count(distinct m.id) as signups from members m
  29. where m.created_at + interval '8' hour >= @start and m.imaginary = 'normal'
  30. group by 1 ) B
  31.  
  32. on A.month = B.month
  33.  
  34. group by 1
Advertisement
Add Comment
Please, Sign In to add comment