Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #set @startDate = "2019-04-17 00:00:00";
- select sum(rm.nr) as nr
- from
- (select
- ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','d2d','oneway','mileage')),0) as rent,
- ifnull((select sum(amount) from payments where state='normal' and r.id=reservation_id and paid_type='coupon'),0) as paid_coupon,
- 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
- from reservations r, members m
- where r.member_id=m.id
- and m.imaginary in ('normal','sofam')
- and r.state = 'completed'
- and convert_tz(r.return_at, '+0:00','+8:00') >= @startdate
- and convert_tz(r.return_at, '+0:00','+8:00') < date_add(@startdate, interval 1 day)
- ) rm
- group by nr;
Advertisement
Add Comment
Please, Sign In to add comment