ahmedrahil786

Quadrant chart basic Info - Rahil

Jul 5th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. select
  2. distinct r.member_id as memberid,
  3. m.display_name as name,
  4. count(r.id) as reservations,
  5. IFNULL(round(B.charges,2),0) as gross_rev,
  6. round((IFNULL(B.charges,0) - IFNULL(A.coupon,0)),2) as net_rev,
  7. round(IFNULL((IFNULL(A.coupon,0)/B.charges),0),2) as coupon_rate
  8. from reservations r
  9. join members m on m.id = r.member_id
  10. left join
  11. (select
  12. p.member_id as mid, month(p.created_at + interval '8' hour) as month,Year(p.created_at + interval '8' hour) as year, IFNULL(p.amount,0) as coupon
  13. from payments p
  14. where p.state = 'normal' and p.paid_type = 'coupon'
  15. group by p.member_id) A
  16. on A.mid = r.member_id
  17. left join
  18. (select
  19. c.member_id as mid, month(c.created_at + interval '8' hour) as month, Year(c.created_at + interval '8' hour) as year, sum(c.amount) as charges
  20. from charges c
  21. where c.state = 'normal' and c.kind IN ('rent' , 'oneway', 'd2d', 'mileage')
  22. group by c.member_id) B
  23. on B.mid = r.member_id
  24. where m.imaginary in ('normal')
  25. and r.member_id not in ('125', '127')
  26. and r.state in ('completed','inUse')
  27. group by memberid
  28. order by gross_rev desc
Advertisement
Add Comment
Please, Sign In to add comment