ahmedrahil786

Charges Breakdown by reservations - For Socar Points

Sep 19th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. select p.reservation_id as prid,p.member_id,r.way,
  2. p.state,
  3. p.type ,
  4. p.point,
  5. date(p.created_at + interval 8 hour) as created_date,
  6. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','oneway','d2d','mileage','toll','penalty','cancelFee','etc','accident','refund',
  7. 'fine','reservationFee','returnFee', 'accidentOpponent', 'parkingFee')),0)),2) as totalcharges,
  8. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent')),0)),2) as rent,
  9. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('d2d')),0)),2) as d2d,
  10. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('mileage')),0)),2) as mileage,
  11. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('toll')),0)),2) as toll,
  12. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('penalty')),0)),2) as penalty,
  13. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('cancelFee')),0)),2) as cancelFee,
  14. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('etc')),0)),2) as etc,
  15. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('accident')),0)),2) as accident,
  16. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('refund')),0)),2) as refund,
  17. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('fine')),0)),2) as fine,
  18. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('reservationFee')),0)),2) as reservationFee,
  19. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('returnFee')),0)),2) as returnFee,
  20. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('accidentOpponent')),0)),2) as accidentOpponent,
  21. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('parkingFee')),0)),2) as parkingFee
  22. from points p left join reservations r on r.id = p.reservation_id
  23. where p.type = 'redeem'
  24. and p.state = 'normal'
  25. and year(p.created_at + interval 8 hour) = '2019'
  26. group by prid
Advertisement
Add Comment
Please, Sign In to add comment