Advertisement
ahmedrahil786

890 W.O.W Tracking - Rahil

Jan 19th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. ############ Query to Find the MFTs whose duration is greater than 3 Hours
  2.  
  3. set @startdate1 = '2020-01-01';
  4. set @startdate2 = '2020-12-01';
  5. use socar_malaysia;
  6. Select Weekofyear(I.return_date) as week, Count(Distinct I.mid) as MFTs from
  7. (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,
  8. A.codes as codes, if(rid2=firstRes,1,0) as mft from
  9. (select
  10. 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,
  11. ifnull((select min(id) from reservations where state='completed' and r.member_id=member_id group by member_id),0) as firstRes,
  12. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  13. Date(r.return_at + interval '8' hour) as return_Date
  14. from reservations r left join members m on r.member_id = m.id
  15. left join member_appendixes ma on ma.member_id = m.id
  16. left join coupons c on c.reservation_id = r.id
  17. where r.state in ('completed','inUse','reserved')
  18. and r.return_at + interval 8 hour >= @startdate1
  19. and r.return_at + interval 8 hour <= @startdate2
  20. and m.imaginary in ('sofam', 'normal')
  21. and r.member_id not in ('125', '127')
  22. group by rid2) A) I
  23. where I.policy_id in ('890')
  24. and I.mft = 1
  25. #and week(I.return_date) >= '46'
  26. group by 1
  27. #and Week(I.return_date) = 2
  28. order by 1 asc ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement