Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @startdate1 = '2020-01-01';
- set @startdate2 = '2020-12-01';
- Select Weekofyear(I.return_date) as week,
- count(distinct case when I.mft = 1 then I.mid end) as MFTs,
- count(distinct case when I.mft = 0 then I.mid end) as MAUs
- from
- (select A.return_date as return_date, A.rid2 as rid,A.mid as mid, A.dur as dur, A.policy_id,
- A.codes as codes, if(rid2=firstRes,1,0) as mft from
- (select
- distinct r.id as rid2, r.member_id as mid, c.code as codes,c.coupon_policy_id as policy_id,
- ifnull((select min(id) from reservations where state='completed' and r.member_id=member_id group by member_id),0) as firstRes,
- round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
- Date(r.return_at + interval '8' hour) as return_Date
- from reservations r left join members m on r.member_id = m.id
- left join coupons c on c.reservation_id = r.id
- where r.state in ('completed','inUse','reserved')
- and r.return_at + interval 8 hour >= @startdate1
- and r.return_at + interval 8 hour <= @startdate2
- and m.imaginary in ('sofam', 'normal')
- and r.member_id not in ('125', '127')
- group by rid2) A
- where A.policy_id in ('890')
- group by 2
- order by 1 asc) I
- group by 1 ;
Advertisement
Add Comment
Please, Sign In to add comment