1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/查询近30天活跃用户数 [user-activity-for-the-past-30-days-i].html

56 lines
2.1 KiB
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>表:<code>Activity</code></p>
2022-03-27 20:37:52 +08:00
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| user_id | int |
| session_id | int |
| activity_date | date |
| activity_type | enum |
+---------------+---------+
2023-12-09 18:42:21 +08:00
该表没有包含重复数据。
activity_type 列是 ENUM(category) 类型, 从 ('open_session' 'end_session' 'scroll_down' 'send_message') 取值。
该表记录社交媒体网站的用户活动。
注意,每个会话只属于一个用户。
2022-03-27 20:37:52 +08:00
</pre>
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p>编写解决方案,统计截至&nbsp;<code>2019-07-27</code>包含2019-07-27<strong>&nbsp;</strong><code>30</code> 天的每日活跃用户数(当天只要有一条活动记录,即为活跃用户)。</p>
2022-03-27 20:37:52 +08:00
<p><strong>任意顺序</strong> 返回结果表。</p>
2023-12-09 18:42:21 +08:00
<p>结果示例如下。</p>
2022-03-27 20:37:52 +08:00
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>
Activity table:
+---------+------------+---------------+---------------+
| user_id | session_id | activity_date | activity_type |
+---------+------------+---------------+---------------+
| 1 | 1 | 2019-07-20 | open_session |
| 1 | 1 | 2019-07-20 | scroll_down |
| 1 | 1 | 2019-07-20 | end_session |
| 2 | 4 | 2019-07-20 | open_session |
| 2 | 4 | 2019-07-21 | send_message |
| 2 | 4 | 2019-07-21 | end_session |
| 3 | 2 | 2019-07-21 | open_session |
| 3 | 2 | 2019-07-21 | send_message |
| 3 | 2 | 2019-07-21 | end_session |
| 4 | 3 | 2019-06-25 | open_session |
| 4 | 3 | 2019-06-25 | end_session |
+---------+------------+---------------+---------------+
<strong>输出:</strong>
+------------+--------------+
| day | active_users |
+------------+--------------+
| 2019-07-20 | 2 |
| 2019-07-21 | 2 |
+------------+--------------+ <strong>
解释:</strong>注意非活跃用户的记录不需要展示。</pre>