Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @start := '2019-1-1';
- select
- A.week,
- count(A.mid) as totalmfts,
- IFNULL(B.Region,"") as Region,
- IFNULL(B.zid,"") as zid,
- IFNULL(B.name,"") as name
- from
- (select
- distinct c.member_id as mid,
- WEEKOFYEAR(c.created_at + interval '8' hour) as Week
- from charges c
- where c.kind = 'subscriptionFee'
- and c.created_at + interval '8' hour >= @start) A
- left join
- (select
- distinct r.member_id as mid,
- min(r.id) as rid,
- z.region as Region,
- z.id as zid,
- z.name as name
- from reservations r
- join members m on r.member_id = m.id
- join zones z on r.start_zone_id = z.id
- where m.imaginary in ('sofam', 'normal')
- and r.member_id not in ('125', '127')
- and r.start_at + interval '8' hour >= @start
- group by r.member_id) B
- on A.mid = B.mid
- where B.Region is not null
- group by A.week,Region,B.zid ;
Advertisement
Add Comment
Please, Sign In to add comment