ahmedrahil786

MFT(Transactions) by Zone, car

Dec 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. set @start := '2019-11-1';
  2. select
  3. A.date,
  4. A.mid,
  5. B.rid as rid,
  6. B.coupon as coupon,
  7. B.car_name as car_name,
  8. B.created_hour as created_hour,
  9. B.region as region
  10. from
  11. (select
  12. distinct c.member_id as mid,
  13. date(c.created_at + interval '8' hour) as date
  14. from charges c
  15. where c.kind = 'subscriptionFee'
  16. and c.created_at + interval '8' hour >= @start) A
  17. left join
  18. (select
  19. distinct r.member_id as mid,
  20. min(r.id) as rid,
  21. IFNULL(co.comment,"") as coupon,
  22. hour(r.created_at + interval '8' hour) as created_hour,
  23. cc.car_name,
  24. z.region as region
  25. from reservations r
  26. left join members m on r.member_id = m.id
  27. left join cars cr on cr.id = r.car_id
  28. left join car_classes cc on cc.id = cr.car_class_id
  29. left join coupons co on co.reservation_id = r.id
  30. left join reservation_appendixes ra on ra.reservation_id = r.id
  31. left join zones z on r.start_zone_id = z.id
  32. where m.imaginary in ('sofam', 'normal')
  33. and r.member_id not in ('125', '127')
  34. and r.start_at + interval '8' hour >= @start
  35. group by r.member_id) B
  36. on A.mid = B.mid
  37. group by A.mid
  38. order by 1 desc
Advertisement
Add Comment
Please, Sign In to add comment