forked from Weitzman-MUSA-GeoCloud/assignment02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery01.sql
More file actions
32 lines (30 loc) · 878 Bytes
/
Copy pathquery01.sql
File metadata and controls
32 lines (30 loc) · 878 Bytes
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
WITH septa_bus_stop_blockgroups AS (
SELECT
stops.stop_id,
'1500000US' || bg.geoid AS geoid
FROM septa.bus_stops AS stops
INNER JOIN census.blockgroups_2020 AS bg
ON ST_DWITHIN(
stops.geog,
ST_TRANSFORM(bg.geog::geometry, 4326)::geography,
800.0
)
WHERE bg.geoid LIKE '42101%'
),
septa_bus_stop_surrounding_population AS (
SELECT
stops.stop_id,
SUM(pop.total) AS estimated_pop_800m
FROM septa_bus_stop_blockgroups AS stops
INNER JOIN census.population_2020 AS pop USING (geoid)
GROUP BY stops.stop_id
)
SELECT
stops.stop_id,
stops.stop_name,
pop.estimated_pop_800m
FROM septa_bus_stop_surrounding_population AS pop
INNER JOIN septa.bus_stops AS stops USING (stop_id)
WHERE pop.estimated_pop_800m > 500
ORDER BY pop.estimated_pop_800m DESC
LIMIT 8;