-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeason_Updates.sql
More file actions
30 lines (30 loc) · 1.09 KB
/
Season_Updates.sql
File metadata and controls
30 lines (30 loc) · 1.09 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
-- First, update all of the records from spring.
UPDATE bikes_2021
SET season = 'Spring'
WHERE started_at >= '2021-03-20 00:00:00'
AND started_at <'2021-06-20 00:00:00'
RETURNING *;
-- Next, update all of the records from summer. This time, let's restrict the returned columns to the most relevant ones.
UPDATE bikes_2021
SET season = 'Summer'
WHERE started_at >= '2021-06-20 00:00:00'
AND started_at < '2021-09-22 00:00:00'
RETURNING started_at, season;
-- Now, update all of the records from autumn.
UPDATE bikes_2021
SET season = 'Autumn'
WHERE started_at >= '2021-09-22 00:00:00'
AND started_at < '2021-12-21 00:00:00'
RETURNING started_at, season;
/* Finally, update the records from winter.
This one's a bit different than the others because you're updating
records from the beginning and the end of the year! */
UPDATE bikes_2021
SET season = 'Winter'
WHERE started_at >= '2021-12-21 00:00:00'
OR started_at < '2021-03-20 00:00:00'
RETURNING started_at, season;
-- Now that all of the seasons have been updated, double-check that nothing was missed.
SELECT season
FROM bikes_2021
WHERE season IS NULL;