forked from Weitzman-MUSA-GeoCloud/assignment02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery07.sql
More file actions
38 lines (36 loc) · 1.05 KB
/
Copy pathquery07.sql
File metadata and controls
38 lines (36 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
with bus_stops_accessible as (
select
stops.stop_id,
stops.wheelchair_boarding,
st_setsrid(
st_makepoint(stops.stop_lon, stops.stop_lat), 4326
)::geography as geog
from septa.bus_stops as stops
),
neighborhood_stats as (
select
n.name as neighborhood_name,
count(*) as total_stops,
count(*) filter (
where s.wheelchair_boarding = 1
) as num_bus_stops_accessible,
count(*) filter (
where s.wheelchair_boarding != 1 or s.wheelchair_boarding is null
) as num_bus_stops_inaccessible
from phl.neighborhoods as n
inner join bus_stops_accessible as s
on st_covers(n.geog, s.geog)
group by n.name
)
select
neighborhood_name,
num_bus_stops_accessible::integer,
num_bus_stops_inaccessible::integer,
round(
num_bus_stops_accessible::numeric
/ nullif(total_stops, 0),
2
) as accessibility_metric
from neighborhood_stats
order by accessibility_metric asc, num_bus_stops_accessible asc
limit 5