forked from musa-5090-spring-2024/assignment01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query08.sql
36 lines (32 loc) · 930 Bytes
/
query08.sql
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
/*
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
start_station AS station_id,
st_setsrid(
ST_MakePoint(start_lon, start_lat), 4326)
AS station_geog,
COUNT(*) AS num_trips
FROM
(SELECT * FROM indego.trips_2021_q3
UNION ALL
SELECT * FROM indego.trips_2022_q3)
AS combined_trips
WHERE
EXTRACT(HOUR FROM start_time) >= 7 AND
EXTRACT(HOUR FROM start_time) < 10
GROUP BY
start_station, start_lon, start_lat
ORDER BY
num_trips DESC
LIMIT 5;
/*
Hint: Use the `EXTRACT` function to get the hour of the day from the
timestamp.
*/