2022-03-27 20:37:52 +08:00
{
"data" : {
"question" : {
"questionId" : "1245" ,
"questionFrontendId" : "1141" ,
"categoryTitle" : "Database" ,
"boundTopicId" : 33169 ,
"title" : "User Activity for the Past 30 Days I" ,
"titleSlug" : "user-activity-for-the-past-30-days-i" ,
2023-12-09 18:42:21 +08:00
"content" : "<p>Table: <code>Activity</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| user_id | int |\n| session_id | int |\n| activity_date | date |\n| activity_type | enum |\n+---------------+---------+\nThis table may have duplicate rows.\nThe activity_type column is an ENUM (category) of type ('open_session', 'end_session', 'scroll_down', 'send_message').\nThe table shows the user activities for a social media website. \nNote that each session belongs to exactly one user.\n</pre>\n\n<p> </p>\n\n<p>Write a solution to find the daily active user count for a period of <code>30</code> days ending <code>2019-07-27</code> inclusively. A user was active on someday if they made at least one activity on that day.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nActivity table:\n+---------+------------+---------------+---------------+\n| user_id | session_id | activity_date | activity_type |\n+---------+------------+---------------+---------------+\n| 1 | 1 | 2019-07-20 | open_session |\n| 1 | 1 | 2019-07-20 | scroll_down |\n| 1 | 1 | 2019-07-20 | end_session |\n| 2 | 4 | 2019-07-20 | open_session |\n| 2 | 4 | 2019-07-21 | send_message |\n| 2 | 4 | 2019-07-21 | end_session |\n| 3 | 2 | 2019-07-21 | open_session |\n| 3 | 2 | 2019-07-21 | send_message |\n| 3 | 2 | 2019-07-21 | end_session |\n| 4 | 3 | 2019-06-25 | open_session |\n| 4 | 3 | 2019-06-25 | end_session |\n+---------+------------+---------------+---------------+\n<strong>Output:</strong> \n+------------+--------------+ \n| day | active_users |\n+------------+--------------+ \n| 2019-07-20 | 2 |\n| 2019-07-21 | 2 |\n+------------+--------------+ \n<strong>Explanation:</strong> Note that we do not care about days with zero active users.\n</pre>\n" ,
2022-03-27 20:37:52 +08:00
"translatedTitle" : "查询近30天活跃用户数" ,
2023-12-09 18:42:21 +08:00
"translatedContent" : "<p>表:<code>Activity</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| user_id | int |\n| session_id | int |\n| activity_date | date |\n| activity_type | enum |\n+---------------+---------+\n该表没有包含重复数据。\nactivity_type 列是 ENUM(category) 类型, 从 ('open_session', 'end_session', 'scroll_down', 'send_message') 取值。\n该表记录社交媒体网站的用户活动。\n注意, 每个会话只属于一个用户。\n</pre>\n\n<p> </p>\n\n<p>编写解决方案,统计截至 <code>2019-07-27</code>( 包含2019-07-27) , 近<strong> </strong><code>30</code> 天的每日活跃用户数(当天只要有一条活动记录,即为活跃用户)。</p>\n\n<p>以 <strong>任意顺序</strong> 返回结果表。</p>\n\n<p>结果示例如下。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\nActivity table:\n+---------+------------+---------------+---------------+\n| user_id | session_id | activity_date | activity_type |\n+---------+------------+---------------+---------------+\n| 1 | 1 | 2019-07-20 | open_session |\n| 1 | 1 | 2019-07-20 | scroll_down |\n| 1 | 1 | 2019-07-20 | end_session |\n| 2 | 4 | 2019-07-20 | open_session |\n| 2 | 4 | 2019-07-21 | send_message |\n| 2 | 4 | 2019-07-21 | end_session |\n| 3 | 2 | 2019-07-21 | open_session |\n| 3 | 2 | 2019-07-21 | send_message |\n| 3 | 2 | 2019-07-21 | end_session |\n| 4 | 3 | 2019-06-25 | open_session |\n| 4 | 3 | 2019-06-25 | end_session |\n+---------+------------+---------------+---------------+\n<strong>输出:</strong>\n+------------+--------------+ \n| day | active_users |\n+------------+--------------+ \n| 2019-07-20 | 2 |\n| 2019-07-21 | 2 |\n+------------+--------------+ <strong>\n解释: </strong>注意非活跃用户的记录不需要展示。</pre>\n" ,
2022-03-27 20:37:52 +08:00
"isPaidOnly" : false ,
"difficulty" : "Easy" ,
2023-12-09 18:42:21 +08:00
"likes" : 119 ,
2022-03-27 20:37:52 +08:00
"dislikes" : 0 ,
"isLiked" : null ,
"similarQuestions" : "[]" ,
"contributors" : [ ] ,
2023-12-09 18:42:21 +08:00
"langToValidPlayground" : "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}" ,
2022-03-27 20:37:52 +08:00
"topicTags" : [
{
"name" : "Database" ,
"slug" : "database" ,
"translatedName" : "数据库" ,
"__typename" : "TopicTagNode"
}
] ,
"companyTagStats" : null ,
"codeSnippets" : [
{
"lang" : "MySQL" ,
"langSlug" : "mysql" ,
"code" : "# Write your MySQL query statement below" ,
"__typename" : "CodeSnippetNode"
} ,
{
"lang" : "MS SQL Server" ,
"langSlug" : "mssql" ,
"code" : "/* Write your T-SQL query statement below */" ,
"__typename" : "CodeSnippetNode"
} ,
{
"lang" : "Oracle" ,
"langSlug" : "oraclesql" ,
"code" : "/* Write your PL/SQL query statement below */" ,
"__typename" : "CodeSnippetNode"
2023-12-09 18:42:21 +08:00
} ,
{
"lang" : "Pandas" ,
"langSlug" : "pythondata" ,
"code" : "import pandas as pd\n\ndef user_activity(activity: pd.DataFrame) -> pd.DataFrame:\n " ,
"__typename" : "CodeSnippetNode"
} ,
{
"lang" : "PostgreSQL" ,
"langSlug" : "postgresql" ,
"code" : "-- Write your PostgreSQL query statement below" ,
"__typename" : "CodeSnippetNode"
2022-03-27 20:37:52 +08:00
}
] ,
2023-12-09 18:42:21 +08:00
"stats" : "{\"totalAccepted\": \"65.6K\", \"totalSubmission\": \"146.2K\", \"totalAcceptedRaw\": 65608, \"totalSubmissionRaw\": 146153, \"acRate\": \"44.9%\"}" ,
2022-03-27 20:37:52 +08:00
"hints" : [ ] ,
"solution" : null ,
"status" : null ,
"sampleTestCase" : "{\"headers\":{\"Activity\":[\"user_id\",\"session_id\",\"activity_date\",\"activity_type\"]},\"rows\":{\"Activity\":[[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\"]]}}" ,
2023-12-09 18:42:21 +08:00
"metaData" : "{\"mysql\":[\"Create table If Not Exists Activity (user_id int, session_id int, activity_date date, activity_type ENUM('open_session', 'end_session', 'scroll_down', 'send_message'))\"],\"mssql\":[\"create table Activity (user_id int, session_id int, activity_date date, activity_type varchar(15) not null check(activity_type in ('open_session', 'end_session', 'scroll_down', 'send_message')))\"],\"oraclesql\":[\"create table Activity (user_id int, session_id int, activity_date date, activity_type varchar(15) not null check(activity_type in ('open_session', 'end_session', 'scroll_down', 'send_message')))\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"user_activity\",\"pythondata\":[\"Activity = pd.DataFrame([], columns=['user_id', 'session_id', 'activity_date', 'activity_type']).astype({'user_id':'Int64', 'session_id':'Int64', 'activity_date':'datetime64[ns]', 'activity_type':'object'})\"],\"postgresql\":[\"Create table If Not Exists Activity (user_id int, session_id int, activity_date date, activity_type VARCHAR(20) CHECK (activity_type IN ('open_session', 'end_session', 'scroll_down', 'send_message')))\\n\"],\"database_schema\":{\"Activity\":{\"user_id\":\"INT\",\"session_id\":\"INT\",\"activity_date\":\"DATE\",\"activity_type\":\"ENUM('open_session', 'end_session', 'scroll_down', 'send_message')\"}}}" ,
2022-03-27 20:37:52 +08:00
"judgerAvailable" : true ,
"judgeType" : "large" ,
"mysqlSchemas" : [
"Create table If Not Exists Activity (user_id int, session_id int, activity_date date, activity_type ENUM('open_session', 'end_session', 'scroll_down', 'send_message'))" ,
"Truncate table Activity" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('1', '1', '2019-07-20', 'open_session')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('1', '1', '2019-07-20', 'scroll_down')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('1', '1', '2019-07-20', 'end_session')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('2', '4', '2019-07-20', 'open_session')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('2', '4', '2019-07-21', 'send_message')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('2', '4', '2019-07-21', 'end_session')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('3', '2', '2019-07-21', 'open_session')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('3', '2', '2019-07-21', 'send_message')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('3', '2', '2019-07-21', 'end_session')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('4', '3', '2019-06-25', 'open_session')" ,
"insert into Activity (user_id, session_id, activity_date, activity_type) values ('4', '3', '2019-06-25', 'end_session')"
] ,
"enableRunCode" : true ,
2023-12-09 18:42:21 +08:00
"envInfo" : "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}" ,
2022-03-27 20:37:52 +08:00
"book" : null ,
"isSubscribed" : false ,
"isDailyQuestion" : false ,
"dailyRecordStatus" : null ,
"editorType" : "CKEDITOR" ,
"ugcQuestionId" : null ,
"style" : "LEETCODE" ,
"exampleTestcases" : "{\"headers\":{\"Activity\":[\"user_id\",\"session_id\",\"activity_date\",\"activity_type\"]},\"rows\":{\"Activity\":[[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\"]]}}" ,
"__typename" : "QuestionNode"
}
}
}