ahmedrahil786

Tracking MFTs from a coupon - Viny

Dec 22nd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1.  
  2.  
  3. set @startdate1 = '2019-08-01';
  4. set @startdate2 = '2020-12-01';
  5. use socar_malaysia;
  6. Select distinct I.mid as mid, I.name as name, Week(I.return_date) as week, I.policy_id as policy_id , I.return_date as MFT_date, I.signup_date as signup_date , I.Coupon_Activated_date as Coupon_Activated_date,
  7. datediff(I.return_date , I.signup_date) as Time_taken_From_Signup_To_MFT,datediff(I.return_date , I.Coupon_Activated_date) as Time_taken_From_Coupon_Activated_To_MFT
  8. from
  9. (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.signup_date as signup_date,
  10. A.Coupon_Activated_date as Coupon_Activated_date, A.codes as codes, if(rid2=firstRes,1,0) as mft from
  11. (select
  12. 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,
  13. ifnull((select min(id) from reservations where state='completed' and r.member_id=member_id group by member_id),0) as firstRes,
  14. Date(m.created_at + interval '8' hour) as signup_date,
  15. Date(c.activated_at + interval '8' hour) as Coupon_Activated_date,
  16. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  17. Date(r.return_at + interval '8' hour) as return_Date
  18. from reservations r left join members m on r.member_id = m.id
  19. left join member_appendixes ma on ma.member_id = m.id
  20. left join coupons c on c.reservation_id = r.id
  21. where r.state in ('completed')
  22. and r.return_at + interval 8 hour >= @startdate1
  23. and r.return_at + interval 8 hour <= @startdate2
  24. and m.imaginary in ('sofam', 'normal')
  25. and r.member_id not in ('125', '127')
  26. group by rid2) A) I
  27. where I.mft = 1
  28. and I.coupon_name like "%iprice%"
  29. #and week(I.return_date) >= '46'
  30. order by I.return_date asc ;
Add Comment
Please, Sign In to add comment