ahmedrahil786

Zone and Week Wise Net Revenues

Jun 19th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. select
  2. weekofyear(r.return_at) as week, r.start_zone_id as zid2, count(r.id) as nuse,
  3. sum(timestampdiff(minute, r.start_at, r.return_at)/60) as dur,
  4. sum((timestampdiff(minute, r.start_at, r.end_at)/60)/24)*12 + if(mod((timestampdiff(minute, r.start_at, r.end_at)/60), 24)>=12,12,mod((timestampdiff(minute, r.start_at, r.end_at)/60), 24)) as adj_dur,
  5. sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','oneway','d2d','mileage')),0)) as rental,
  6. sum(ifnull((select sum(amount) from payments where state='normal' and reservation_id=r.id and paid_type ='coupon'),0)) as discount
  7. #count(distinct m.id) as mau
  8. from reservations r, members m , zones z
  9. where r.member_id=m.id
  10. and r.start_zone_id = z.id
  11. and r.way in ('round','d2d','oneway')
  12. and r.state = 'completed'
  13. and m.imaginary in ('normal', 'sofam')
  14. and r.return_at+interval 8 hour >= @start
  15. and r.start_zone_id not in (2,3,101,383,378,697,712,818)
  16. group by week, zid2
Advertisement
Add Comment
Please, Sign In to add comment