ahmedrahil786

Round Vs D2d Vs One way - Included MFT, MAU- M.O.M - Rahil

Sep 24th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. set @startdate1 = '2019-01-01';
  2. set @startdate2 = '2019-09-01';
  3. use socar_malaysia;
  4. select A.return_date as date, A.rid2 as rid, A.mid as mid, A.dur as dur, A.ad_sdur as ad_sdur, A.way as way,
  5. IFNULL(E.charges,0) as gross_rev,
  6. IFNULL(F.coupon_Spent,0) as Coupon_Spent,
  7. round((IFNULL(E.charges,0) - IFNULL(F.coupon_Spent,0)),2) as net_rev, if(rid2=firstRes,1,0) as mft from
  8. (select
  9. distinct r.id as rid2, r.member_id as mid, r.way as way,
  10. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  11. round(sum(floor(timestampdiff(minute, r.start_at, r.end_at)/60/24)*12+if(mod(timestampdiff(hour, r.start_at, r.end_at),24)>=12,12,mod(timestampdiff(minute, r.start_at, r.end_at)/60,24))),2) as ad_sdur,
  12. Date(r.return_at + interval '8' hour) as return_Date,
  13. ifnull((select min(id) from reservations where state='completed' and r.member_id=member_id group by member_id),0) as firstRes
  14. from reservations r left join members m on r.member_id = m.id
  15. where r.state in ('completed')
  16. and r.return_at + interval 8 hour >= @startdate1
  17. and r.return_at + interval 8 hour <= @startdate2
  18. and m.imaginary in ('sofam', 'normal')
  19. and r.member_id not in ('125', '127')
  20. and (YEAR(r.start_at) - YEAR(m.birthday)) < 100
  21. group by rid2) A
  22. left join
  23. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  24. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage')
  25. group by rid) E on A.rid2 = E.rid
  26. left join
  27. (select p.reservation_id as rid, month(p.created_at + interval '8' hour) as month,Year(p.created_at + interval '8' hour) as year, IFNULL(p.amount,0) as coupon_Spent from payments p
  28. where p.state = 'normal' and p.paid_type = 'coupon'
  29. group by p.reservation_id) F on A.rid2 = F.rid
Advertisement
Add Comment
Please, Sign In to add comment