ahmedrahil786

Rahil-Mineng Query 2- Half

May 4th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #reservation return at###############################################################################################################################
  2. use socar_malaysia;
  3.  
  4. select
  5. distinct z.id as zoneid,
  6. z.region as region,
  7. z.name as zonename,
  8. datediff(now(),z.created_at) as daysdeployed,
  9. #date_format(convert_tz(r.return_at, '+00:00', '+8:00'),'%Y-%m-%d') as date,
  10. (select count(czl.id) from car_zone_logs czl where czl.zone_state='normal'and czl.zone_id = zoneid and date_format(convert_tz(r.return_at, '+00:00', '+8:00'),'%Y-%m-%d')=date_format(czl.log_date+interval 8 hour, "%Y-%m-%d")) as ncars,
  11. count(r.id) as nuse,
  12. count(if(r.way='round', r.id, null)) as nuse_rnd,
  13. count(if(r.way='d2d', r.id, null)) as res_d2d,
  14. count(distinct r.car_id) as ncar_used,
  15. count(distinct z.id) as nzone,
  16. count(distinct m.id) as nmem,
  17. #count(if(r.way='oneway', r.id, null)) as res_ow,
  18. sum(ra.mileage) as rmil,
  19. sum(timestampdiff(minute, r.start_at, r.end_at)/60) as dur,
  20. #sum(floor(timestampdiff(minute, r.start_at, r.end_at)/60/24)*12+if(mod(timestampdiff(hour, r.start_at, r.end_at),24)>=12,12,mod(timestampdiff(minute, r.start_at, r.end_at)/60,24))) as ad_sdur,
  21. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','oneway','d2d','mileage')),0)),2) as revenues,
  22. round(sum(ifnull((select sum(amount) from payments where state='normal' and reservation_id=r.id and paid_type ='coupon'),0)),2) as coupons,
  23. round(sum(ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','oneway','d2d','mileage')),0)
  24. - ifnull((select sum(amount) from payments where state='normal' and reservation_id=r.id and paid_type ='coupon'),0)),2) as nr
  25.  
  26.  
  27. from zones z, reservations r, members m, reservation_appendixes ra
  28.  
  29. Where
  30. r.start_zone_id = z.id
  31. and r.member_id = m.id
  32. and r.id = ra.reservation_id
  33. and m.imaginary in ('sofam', 'normal')
  34. and r.member_id not in ('125', '127')
  35. and z.id not in (2, 3, 101)
  36. and r.state in ('completed')
  37. and r.return_at + interval 8 hour >= '2019-01-01'
  38. and r.return_at + interval 8 hour <= '2019-01-03'
  39.  
  40. group by z.id
  41. order by z.id desc
  42. ;
Advertisement
Add Comment
Please, Sign In to add comment