ahmedrahil786

Mineng Query - Biz Index Dashboard - daily

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