Skip to content

Commit 836b95c

Browse files
refactor 1141
1 parent f5f1d41 commit 836b95c

File tree

1 file changed

+0
-49
lines changed

1 file changed

+0
-49
lines changed

database/_1141.sql

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,3 @@
1-
--1141. User Activity for the Past 30 Days I
2-
--
3-
--Table: Activity
4-
--
5-
--+---------------+---------+
6-
--| Column Name | Type |
7-
--+---------------+---------+
8-
--| user_id | int |
9-
--| session_id | int |
10-
--| activity_date | date |
11-
--| activity_type | enum |
12-
--+---------------+---------+
13-
--There is no primary key for this table, it may have duplicate rows.
14-
--The activity_type column is an ENUM of type ('open_session', 'end_session', 'scroll_down', 'send_message').
15-
--The table shows the user activities for a social media website.
16-
--Note that each session belongs to exactly one user.
17-
--
18-
--
19-
--Write an SQL query to find the daily active user count for a period of 30 days ending 2019-07-27 inclusively. A user was active on some day if he/she made at least one activity on that day.
20-
--
21-
--The query result format is in the following example:
22-
--
23-
--Activity table:
24-
--+---------+------------+---------------+---------------+
25-
--| user_id | session_id | activity_date | activity_type |
26-
--+---------+------------+---------------+---------------+
27-
--| 1 | 1 | 2019-07-20 | open_session |
28-
--| 1 | 1 | 2019-07-20 | scroll_down |
29-
--| 1 | 1 | 2019-07-20 | end_session |
30-
--| 2 | 4 | 2019-07-20 | open_session |
31-
--| 2 | 4 | 2019-07-21 | send_message |
32-
--| 2 | 4 | 2019-07-21 | end_session |
33-
--| 3 | 2 | 2019-07-21 | open_session |
34-
--| 3 | 2 | 2019-07-21 | send_message |
35-
--| 3 | 2 | 2019-07-21 | end_session |
36-
--| 4 | 3 | 2019-06-25 | open_session |
37-
--| 4 | 3 | 2019-06-25 | end_session |
38-
--+---------+------------+---------------+---------------+
39-
--
40-
--Result table:
41-
--+------------+--------------+
42-
--| day | active_users |
43-
--+------------+--------------+
44-
--| 2019-07-20 | 2 |
45-
--| 2019-07-21 | 2 |
46-
--+------------+--------------+
47-
--Note that we do not care about days with zero active users.
48-
49-
--# Write your MySQL query statement below
501
select activity_date as day, count(distinct(user_id)) as active_users from Activity
512
where activity_date between "2019-06-28" and "2019-07-27"
523
group by activity_date;

0 commit comments

Comments
 (0)