forked from Weitzman-MUSA-GeoCloud/assignment01
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery07.sql
More file actions
34 lines (25 loc) · 862 Bytes
/
Copy pathquery07.sql
File metadata and controls
34 lines (25 loc) · 862 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
/*
How many trips started on one day and ended on a different day?
Your result should have one column named trip_year, one column named
trip_quarter, and one column named num_trips.
*/
-- Enter your SQL query here
select
2021 as trip_year,
3 as trip_quarter,
count(*) as num_trips
from indego.trips_2021_q3
where start_time::date <> end_time::date
union all
select
2022 as trip_year,
3 as trip_quarter,
count(*) as num_trips
from indego.trips_2022_q3
where start_time::date <> end_time::date;
/*
Hint 1: when you cast a TIMESTAMP to a DATE the time component of the value is simply stripped off
Hint 2: Years, quarters, and other parts of DATEs or TIMESTAMPs can be retrieved from a TIMESTAMP using the
[EXTRACT](https://www.postgresql.org/docs/12/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT)
function.
*/