forked from Weitzman-MUSA-GeoCloud/assignment01
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery08.sql
More file actions
37 lines (33 loc) · 976 Bytes
/
Copy pathquery08.sql
File metadata and controls
37 lines (33 loc) · 976 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
33
34
35
36
37
/*
Give the five most popular starting stations across all years between 7am
and 9:59am.
Your result should have 5 records with three columns, one for the station id
(named `station_id`), one for the point geography of the station (named
`station_geog`), and one for the number of trips that started at that
station (named `num_trips`).
*/
-- Enter your SQL query here
select
s.id as station_id,
s.geog as station_geog,
t.num_trips as num_trips
from (
select
start_station,
count(*) as num_trips
from (
select start_station, start_time from indego.trips_2021_q3
union all
select start_station, start_time from indego.trips_2022_q3
) trips
where extract(hour from start_time) between 7 and 9
group by start_station
) t
join indego.station_statuses s
on s.id::text = t.start_station
order by t.num_trips desc
limit 5;
/*
Hint: Use the `EXTRACT` function to get the hour of the day from the
timestamp.
*/