Skip to content

Commit ac21a09

Browse files
committed
Upload 118
1 parent 6df60e6 commit ac21a09

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ To make the daily tasks of creating a new file and updating the index easier, th
146146
| 115 | [Immediate Food Delivery II](https://leetcode.com/problems/immediate-food-delivery-ii/description/) | [Solution](solutions/115_immediate_food_delivery_ii.md) | LeetCode | Medium | |
147147
| 116 | [Game Play Analysis IV](https://leetcode.com/problems/game-play-analysis-iv/description/) | [Solution](solutions/116_game_play_analysis_iv.md) | LeetCode | Medium | |
148148
| 117 | [Number of Unique Subjects Taught by Each Teacher](https://leetcode.com/problems/number-of-unique-subjects-taught-by-each-teacher/description/) | [Solution](solutions/117_number_of_unique_subjects_taught_by_each_teacher.md) | LeetCode | Easy | |
149+
| 118 | [User Activity for the Past 30 Days I](https://leetcode.com/problems/user-activity-for-the-past-30-days-i/description/) | [Solution](solutions/118_user_activity_for_the_past_30_days_i.md) | LeetCode | Easy | `BETWEEN`, `DATE` w/ `INTERVAL` |
149150

150151
## Author(s)
151152

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SQL Everyday \#118
2+
3+
## User Activity for the Past 30 Days I
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
Write a solution to find the daily active user count for a period of `30` days ending `2019-07-27` inclusively. A user was active on someday if they made at least one activity on that day.
11+
12+
Return the result table in *any order*. [[Full Description](https://leetcode.com/problems/user-activity-for-the-past-30-days-i/description/)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
SELECT
19+
activity_date AS day
20+
,COUNT(DISTINCT user_id) AS active_users
21+
FROM Activity
22+
WHERE activity_date BETWEEN DATE('2019-07-28' - INTERVAL 30 DAY) AND '2019-07-28'
23+
GROUP BY activity_date
24+
;
25+
```
26+
27+
## Site Solution
28+
29+
```sql
30+
-- LeetCode Solution
31+
SELECT
32+
activity_date AS day,
33+
COUNT(DISTINCT user_id) AS active_users
34+
FROM
35+
Activity
36+
WHERE
37+
DATEDIFF('2019-07-27', activity_date) < 30 AND DATEDIFF('2019-07-27', activity_date)>=0
38+
GROUP BY 1
39+
```
40+
41+
## Notes
42+
43+
TODO
44+
45+
Go to [Table of Contents](/README.md#contents)\
46+
Go to [Overview](/README.md)

0 commit comments

Comments
 (0)