ahmedrahil786

Total fuel cost - Rahil

May 6th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. select A.month as month, A.year as year, ifnull(A.amount,0) as Fuel_card_amount, ifnull(B.Amount,0) as petrol_reimbursement ,
  2. ifnull(A.amount,0)+ifnull(B.Amount,0) as total_fuel_Cost
  3. from
  4. (select
  5. month(fu.created_at + interval 8 hour) as month,
  6. year(fu.created_at + interval 8 hour) as year,
  7. ifnull(sum(fu.amount),0) as amount
  8. from fuel_card_uses fu
  9. group by 1,2 ) A
  10. left join
  11. (select
  12. month(fr.created_at + interval 8 hour) as month,
  13. year(fr.created_at + interval 8 hour) as year,
  14. ifnull(sum(fr.requested_amount),0) as amount
  15. from fuel_reimbursements fr
  16. group by 1,2 ) B
  17. on A.month = B.month and A.year = B.year
  18. group by 1,2
  19. order by 2 asc,1 asc
Advertisement
Add Comment
Please, Sign In to add comment