ahmedrahil786

L56 data - Reservation dump - Tree chart

Mar 19th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. Select L.*, If(L.mrid = L.rid, 1,0), datediff(L.Resv_date1, L.MFT_date) as diff from
  2. (select A.mid as mid,A.name as name, A.rid as rid, B.mrid as mrid, A.coupon as coupon, A.car_name as car_name, (A.age) as age, A.dur as dur,IFNULL(E.charges,0) as gross_rev,
  3. IFNULL(F.coupon_Spent,0) as Coupon_Spent, round((IFNULL(E.charges,0) - IFNULL(F.coupon_Spent,0)),2) as net_rev, B.date as MFT_date, A.date as Resv_date1 from
  4. (select r.id as rid, cc.car_name as car_name, IFNULL(co.comment,"") as coupon, r.member_id as mid,m.display_name as name, Date(r.return_at + interval 8 hour) as Date,
  5. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,(YEAR(r.start_at) - YEAR(m.birthday)) as age
  6. from reservations r left join members m on m.id = r.member_id
  7. left join cars cr on cr.id = r.car_id
  8. left join car_classes cc on cc.id = cr.car_class_id
  9. left join coupons co on co.reservation_id = r.id
  10. where r.state = 'completed'
  11. and m.imaginary in ('sofam', 'normal')
  12. and r.member_id not in ('125', '127')
  13. group by 1) A
  14. left join
  15. (select distinct r.member_id as mid, min(r.id) as mrid, date(r.return_at + interval 8 hour) as date
  16. from reservations r left join members m on m.id = r.member_id
  17. where r.state = 'completed'
  18. and m.imaginary in ('sofam', 'normal')
  19. and r.member_id not in ('125', '127')
  20. group by 1) B
  21. on A.mid = B.mid
  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.rid = 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.rid = F.rid
  30. order by 1,2 asc) L
  31. where datediff(L.Resv_date1, L.MFT_date) < '57'
  32. group by 1,3 ;
Add Comment
Please, Sign In to add comment