ahmedrahil786

One way Trip - Airport - Hoon and Rahil _ V2.0

Jul 3rd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. Select A.mid as memberid,
  2. B.rid as rid,
  3. B.way as way,
  4. B.reservationdate as res_date,
  5. Date(C.MFTDate) as MFTdate,
  6. date(C.lastactivedate) as lastactivedate,
  7. IFNULL(ROUND(D.rev,2),0) as gross_amount,
  8. ROUND(IFNULL(E.coupon,0),1) as coupon_amount,
  9. Round((IFNULL(D.rev,0) - IFNULL(E.coupon,0)),2) as net_rev
  10. from
  11. (select fb.mid
  12. from
  13. (select
  14. distinct r.member_id as mid, min(r.id) as rid, r.way as way, m.email as email, r.start_zone_id as stid, r.end_zone_id as edid, r.state as state , Date(r.return_at + interval 8 hour) as date
  15. from reservations r
  16. join members m on m.id = r.member_id
  17. where r.state = 'completed' and m.state = 'normal' and m.imaginary = 'normal' and m.email not like '%socar.my%'
  18. group by r.member_id) fb
  19. where fb.way in ('oneway','onewayReturn') and fb.email not like '%socar.my%' and fb.stid in ('244','245') or fb.edid in ('244','245') and fb.date > '2019-06-01') A
  20. join
  21. (select
  22. m.id as memberid,
  23. r.id as rid,
  24. r.way as way,
  25. Date(r.start_at + interval '8' hour) as reservationdate
  26. from members m
  27. left outer join reservations r on m.id = r.member_id
  28. Where r.start_at != 0 and m.imaginary = 'normal' and r.state = 'completed'
  29. group by m.id,r.id) B on B.memberid = A.mid
  30. left join
  31. (select
  32. m.id as memberid,
  33. TIMESTAMPDIFF(YEAR, str_to_date(m.birthday, '%Y%m%d'), Now()) AS age,
  34. min(r.start_at + interval '8' hour) as MFTdate,
  35. Max(r.start_at + interval '8' hour) as lastactivedate
  36. from members m
  37. left outer join reservations r on m.id = r.member_id
  38. join charges c on m.id = c.member_id
  39. Where r.start_at != 0
  40. and m.imaginary = 'normal'
  41. and c.kind = 'subscriptionFee'
  42. and r.state = 'completed'
  43. group by m.id) C on B.memberid = C.memberid
  44. left join
  45. (select sum(c.amount) as rev, c.reservation_id as rid
  46. from charges c
  47. where c.state = 'normal' and c.kind IN ('rent' , 'oneway', 'd2d', 'mileage')
  48. group by c.reservation_id) as D ON B.rid = D.rid
  49. left join
  50. (select IFNULL(p.amount,0) as coupon, p.reservation_id as rid
  51. from payments p
  52. where p.state = 'normal' and p.paid_type = 'coupon') as E on E.rid = B.rid
  53. order by A.mid
Advertisement
Add Comment
Please, Sign In to add comment