ahmedrahil786

Loui Query - Zones, cars - Dashboard -Daily Index File share

May 6th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. select cz.team, cz.region, cz.zid, cz.zname, cz.cid, cz.plate, cz.ctype, cz.op_day,
  2. ifnull(sum(rm.nuse),0) as nuse, ifnull(sum(rm.rnd),0) as round, ifnull(sum(rm.d2d),0) as d2d, ifnull(sum(rm.oneway),0) as oneway, ifnull(sum(rm.onewayreturn),0) as onewayreturn,
  3. ifnull(sum(rm.dur),0) as dur, ifnull(sum(rm.nmember),0) as memeber, ifnull(sum(rm.NR),0) as NR#, (ifnull(sum(rm.rent),0)) - (ifnull(sum(rm.paid_coupon),0)) as rn
  4.  
  5. from
  6. (select cz.zone_id as zid, z.region as region, z.city as team, z.name as zname, cz.car_id as cid, c.registration_no as plate, c.car_class_id as class, (select car_classes.car_name from car_classes where car_classes.id=c.car_class_id) as ctype, count(cz.id) as op_day,
  7. date_sub(cz.log_date, interval 1 day) as czdate
  8. from car_zone_logs cz, zones z, cars c
  9. where cz.zone_id=z.id
  10. and cz.car_id=c.id
  11. and z.id not in (2,3,101,383,378,697,712,818)
  12. and date_sub(cz.log_date+interval 8 hour, interval 1 day) between ('2019-02-01 00:00:00') and ('2019-04-31 23:59:59')
  13. group by cid, zid
  14. order by cid
  15. )cz
  16. left join
  17. (select
  18. r.car_id as cid2,
  19. r.start_zone_id as zid2,
  20. count(r.id) as nuse,
  21. count(if(r.way='round', r.id, null)) as rnd,
  22. count(if(r.way='d2d', r.id, null)) as d2d,
  23. count(if(r.way='oneway', r.id, null)) as oneway,
  24. count(if(r.way='onewayreturn', r.id, null)) as onewayreturn,
  25. count(distinct r.member_id) as nmember,
  26. sum(timestampdiff(hour, r.start_at, r.end_at)) as dur,
  27. ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','d2d','mileage')),0) as rent,
  28. ifnull((select sum(amount) from payments where state='normal' and r.id=reservation_id and paid_type='coupon'),0) as paid_coupon,
  29. 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))) as NR,
  30. date_format(convert_tz(r.return_at, '+00:00', '+8:00'),'%Y-%m-%d') as czdate2
  31. from reservations r, members m
  32. where
  33. r.member_id=m.id
  34. and m.imaginary in ('normal','sofam')
  35. and r.way in ('round','d2d','oneway')
  36. and r.state = 'completed'
  37. and r.return_at+interval 8 hour between ('2019-02-01 00:00:00') and ('2019-04-31 23:59:59')
  38. group by cid2, zid2, czdate2
  39. order by cid2
  40. ) rm
  41. on ( cz.zid=rm.zid2 and cz.cid=rm.cid2)
  42. group by cz.zid, cz.cid
  43. order by cz.zid, op_day desc, cz.cid
Advertisement
Add Comment
Please, Sign In to add comment