Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############ Query to Find the MFTs whose duration is greater than 3 Hours
- set @startdate1 = '2020-01-01';
- set @startdate2 = '2020-12-01';
- use socar_malaysia;
- Select Weekofyear(I.return_date) as week, Count(Distinct I.mid) as MFTs from
- (select A.return_date as return_date, A.rid2 as rid,A.mid as mid, A.dur as dur, A.name as name, A.email as email, A.phone as phone, A.coupon_name as coupon_name, 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, m.display_name as name, m.email as email, ma.phone as phone, c.comment as coupon_name, 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 member_appendixes ma on ma.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) I
- where I.policy_id in ('890')
- and I.mft = 1
- #and week(I.return_date) >= '46'
- group by 1
- #and Week(I.return_date) = 2
- order by 1 asc ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement