ahmedrahil786

Not Working - Daily Index Query

May 5th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. Select
  2. *
  3. from
  4.  
  5. (select
  6. distinct z.id as zoneid,
  7. z.region as region,
  8. z.name as zonename,
  9. datediff(now(),z.created_at) as daysdeployed
  10. from zones z) A
  11.  
  12. left join
  13.  
  14. (select
  15. czl.zone_id as zoneid,
  16. count(czl.id) as ncars
  17. from car_zone_logs czl
  18. where czl.zone_state='normal'
  19. #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"))
  20. group by zoneid
  21. )B
  22.  
  23. on B.zoneid = A.zoneid
  24.  
  25. left join
  26.  
  27. (select
  28. z.id as zoneid,
  29. count(r.id) as nuse,
  30. count(if(r.way='round', r.id, null)) as nuse_rnd,
  31. count(if(r.way='d2d', r.id, null)) as res_d2d,
  32. count(distinct r.car_id) as ncar_used,
  33. count(distinct z.id) as nzone,
  34. count(distinct m.id) as nmem,
  35. #count(if(r.way='oneway', r.id, null)) as res_ow,
  36. sum(ra.mileage) as rmil,
  37. sum(timestampdiff(minute, r.start_at, r.end_at)/60) as dur
  38.  
  39. from zones z
  40.  
  41. left join reservations r
  42. on r.start_zone_id = z.id
  43.  
  44. left join members m
  45. on r.member_id = m.id
  46.  
  47. left join reservation_appendixes ra
  48. on ra.reservation_id = r.id
  49.  
  50. group by z.id
  51. ) c
  52.  
  53. on c.zoneid = A.zoneid
  54.  
  55.  
  56. ###### Not workking
  57.  
  58. select
  59.  
  60. distinct z.id as zoneid,
  61. count(distinct r.id) as nuse,
  62. 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
  63.  
  64. from zones z
  65.  
  66. left join reservations r
  67. on r.start_zone_id = z.id
  68.  
  69. left join charges ch
  70. on ch.reservation_id = r.id
  71.  
  72. left join payments p
  73. on p.reservation_id = r.id
  74.  
  75. where r.return_at + interval 8 hour >= '2019-01-01'
  76. and r.return_at + interval 8 hour <= '2019-01-03'
  77.  
  78. group by zoneid
Advertisement
Add Comment
Please, Sign In to add comment