Advertisement
ahmedrahil786

50% off tracking - Rahil

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