ahmedrahil786

Loui query to revenues

Apr 17th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #set @startDate = "2019-04-17 00:00:00";
  2. select sum(rm.nr) as nr
  3. from
  4. (select
  5. ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','d2d','oneway','mileage')),0) as rent,
  6. ifnull((select sum(amount) from payments where state='normal' and r.id=reservation_id and paid_type='coupon'),0) as paid_coupon,
  7. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','oneway','d2d','mileage')),0)- ifnull((select sum(amount) from payments where state='normal' and reservation_id=r.id and paid_type ='coupon'),0)),2) as nr
  8. from reservations r, members m
  9. where r.member_id=m.id
  10. and m.imaginary in ('normal','sofam')
  11. and r.state = 'completed'
  12. and convert_tz(r.return_at, '+0:00','+8:00') >= @startdate
  13. and convert_tz(r.return_at, '+0:00','+8:00') < date_add(@startdate, interval 1 day)
  14.  
  15.  
  16. ) rm
  17. group by nr;
Advertisement
Add Comment
Please, Sign In to add comment