Skip to content

Commit c0a1c09

Browse files
add 1141
1 parent cd3d45d commit c0a1c09

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ _If you like this project, please leave me a star._ ★
854854
|1179|[Reformat Department Table](https://leetcode.com/problems/reformat-department-table/)|[Solution](../master/database/_1179.sql) | | Easy |
855855
|1173|[Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i/)|[Solution](../master/database/_1173.sql) | | Easy |
856856
|1148|[Article Views I](https://leetcode.com/problems/article-views-i/)|[Solution](../master/database/_1148.sql) | | Easy |
857+
|1141|[User Activity for the Past 30 Days I](https://leetcode.com/problems/user-activity-for-the-past-30-days-i/)|[Solution](../master/database/_1141.sql) | | Easy |
857858
|1084|[Sales Analysis III](https://leetcode.com/problems/sales-analysis-iii/)|[Solution](../master/database/_1084.sql) | | Easy |
858859
|1083|[Sales Analysis II](https://leetcode.com/problems/sales-analysis-ii/)|[Solution](../master/database/_1083.sql) | | Easy |
859860
|1082|[Sales Analysis I](https://leetcode.com/problems/sales-analysis-i/)|[Solution](../master/database/_1082.sql) | | Easy |

database/_1141.sql

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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
50+
select activity_date as day, count(distinct(user_id)) as active_users from Activity
51+
where activity_date between "2019-06-28" and "2019-07-27"
52+
group by activity_date;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy