How to Add or Subtract Time Units - StrataScratch 2
How to Add or Subtract Time Units - StrataScratch 2
Pricing
Back to guide
Modules
How to Add or Subtract Time Units?
Main Topics
→ 2001-02-28 01:00:00
Alternative: DATEDIFF()
Guided Practice
Table: fb_comments_count
2019-12-
18 1
29
2019-12-
25 1
21
2020-01-
78 1
04
2020-02-
37 1
01
2019-12-
41 1
23
Tables:
PostgreS…
fb_comments_count
SELECT user_id,
number_of_comments,
created_at,
timestamp '2020-02-10' AS end_date
FROM fb_comments_count
All required columns and the >rst 5 rows of the solution are shown
2019-12-
18 1
29
2019-12-
25 1
21
2020-01-
78 1
04
2020-02-
37 1
01
2019-12-
41 1
23
All required columns and the >rst 5 rows of the solution are shown
2019-12-
18 1
29
2019-12-
25 1
21
2020-01-
78 1
04
2020-02-
37 1
01
2019-12-
41 1
23
All required columns and the >rst 5 rows of the solution are shown
2020-02-
37 1
01
2020-02-
99 1
02
2020-01-
18 1
31
2020-01-
58 1
26
2020-02-
24 1
03
SELECT user_id,
SUM(number_of_comments)AS number_of_comment
FROM fb_comments_count
WHERE created_at BETWEEN timestamp '2020-02-10' -
GROUP BY user_id
All required columns and the >rst 5 rows of the solution are shown
user_id number_of_comments
5 1
8 4
9 2
16 1
18 2
SELECT user_id,
SUM(number_of_comments) AS number_of_commen
FROM fb_comments_count
WHERE created_at BETWEEN DATE_SUB('2020-02-10', IN
GROUP BY user_id
Tables:
PostgreS…
fb_comments_count
1 SELECT user_id,
2 SUM(number_of_comments)AS
number_of_comments
3 FROM fb_comments_count
4 WHERE created_at BETWEEN timestamp '2020-02
-10' - 30 * INTERVAL '1 day' AND
timestamp '2020-02-10'
5 GROUP BY user_id