parking_area.txt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. -- 区域饱和度
  2. select
  3. area_name,
  4. ifnull(round(occupancy_parking_number*100/total_parking_number,2),0)
  5. from
  6. (SELECT
  7. area_id,
  8. area_name,
  9. CASE
  10. WHEN
  11. sum( remain_parking_number ) IS NULL THEN
  12. 0 ELSE sum( remain_parking_number )
  13. END remain_parking_number,-- 空闲位
  14. CASE
  15. WHEN sum( total_parking_number ) - sum( remain_parking_number ) IS NULL THEN
  16. 0 ELSE sum( total_parking_number ) - sum( remain_parking_number )
  17. END occupancy_parking_number, -- 占用位
  18. CASE
  19. WHEN sum( total_parking_number ) IS NULL THEN
  20. 0 ELSE sum( total_parking_number ) END as total_parking_number
  21. FROM
  22. luo_park_baseinfo t
  23. LEFT JOIN luo_parking_berths a ON t.park_id = a.park_id
  24. AND a.CREATE_TIME = ( SELECT max( CREATE_TIME ) max_time FROM luo_parking_berths )
  25. group by 1,2) t1
  26. -- 饱和度时段分析
  27. select hour_flag,
  28. ifnull(round(sum(occupancy_parking_number)*100/sum(total_parking_number),2),0)
  29. from (SELECT
  30. park_id,
  31. HOUR(CREATE_TIME) as HOUR_flag,
  32. max(total_parking_number) total_parking_number,
  33. min(remain_parking_number) remain_parking_number,
  34. max(total_parking_number)-min(remain_parking_number) as occupancy_parking_number
  35. FROM
  36. luo_parking_berths
  37. where remain_parking_number>=0
  38. group by 1,2) a
  39. group by 1