mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
92 lines
11 KiB
JSON
92 lines
11 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "1892",
|
||
"questionFrontendId": "1741",
|
||
"categoryTitle": "Database",
|
||
"boundTopicId": 583581,
|
||
"title": "Find Total Time Spent by Each Employee",
|
||
"titleSlug": "find-total-time-spent-by-each-employee",
|
||
"content": "<p>Table: <code>Employees</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| emp_id | int |\n| event_day | date |\n| in_time | int |\n| out_time | int |\n+-------------+------+\n(emp_id, event_day, in_time) is the primary key (combinations of columns with unique values) of this table.\nThe table shows the employees' entries and exits in an office.\nevent_day is the day at which this event happened, in_time is the minute at which the employee entered the office, and out_time is the minute at which they left the office.\nin_time and out_time are between 1 and 1440.\nIt is guaranteed that no two events on the same day intersect in time, and in_time < out_time.\n</pre>\n\n<p> </p>\n\n<p>Write a solution to calculate the total time <strong>in minutes</strong> spent by each employee on each day at the office. Note that within one day, an employee can enter and leave more than once. The time spent in the office for a single entry is <code>out_time - in_time</code>.</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> \nEmployees table:\n+--------+------------+---------+----------+\n| emp_id | event_day | in_time | out_time |\n+--------+------------+---------+----------+\n| 1 | 2020-11-28 | 4 | 32 |\n| 1 | 2020-11-28 | 55 | 200 |\n| 1 | 2020-12-03 | 1 | 42 |\n| 2 | 2020-11-28 | 3 | 33 |\n| 2 | 2020-12-09 | 47 | 74 |\n+--------+------------+---------+----------+\n<strong>Output:</strong> \n+------------+--------+------------+\n| day | emp_id | total_time |\n+------------+--------+------------+\n| 2020-11-28 | 1 | 173 |\n| 2020-11-28 | 2 | 30 |\n| 2020-12-03 | 1 | 41 |\n| 2020-12-09 | 2 | 27 |\n+------------+--------+------------+\n<strong>Explanation:</strong> \nEmployee 1 has three events: two on day 2020-11-28 with a total of (32 - 4) + (200 - 55) = 173, and one on day 2020-12-03 with a total of (42 - 1) = 41.\nEmployee 2 has two events: one on day 2020-11-28 with a total of (33 - 3) = 30, and one on day 2020-12-09 with a total of (74 - 47) = 27.\n</pre>\n",
|
||
"translatedTitle": "查找每个员工花费的总时间",
|
||
"translatedContent": "<p>表: <code>Employees</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| emp_id | int |\n| event_day | date |\n| in_time | int |\n| out_time | int |\n+-------------+------+\n在 SQL 中,(emp_id, event_day, in_time) 是这个表的主键。\n该表显示了员工在办公室的出入情况。\nevent_day 是此事件发生的日期,in_time 是员工进入办公室的时间,而 out_time 是他们离开办公室的时间。\nin_time 和 out_time 的取值在1到1440之间。\n题目保证同一天没有两个事件在时间上是相交的,并且保证 in_time 小于 out_time。\n</pre>\n\n<p> </p>\n\n<p>计算每位员工每天在办公室花费的总时间(以分钟为单位)。 请注意,在一天之内,同一员工是可以多次进入和离开办公室的。 在办公室里一次进出所花费的时间为out_time 减去 in_time。</p>\n\n<p>返回结果表单的顺序无要求。<br />\n查询结果的格式如下:</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\nEmployees table:\n+--------+------------+---------+----------+\n| emp_id | event_day | in_time | out_time |\n+--------+------------+---------+----------+\n| 1 | 2020-11-28 | 4 | 32 |\n| 1 | 2020-11-28 | 55 | 200 |\n| 1 | 2020-12-03 | 1 | 42 |\n| 2 | 2020-11-28 | 3 | 33 |\n| 2 | 2020-12-09 | 47 | 74 |\n+--------+------------+---------+----------+\n<strong>输出:</strong>\n+------------+--------+------------+\n| day | emp_id | total_time |\n+------------+--------+------------+\n| 2020-11-28 | 1 | 173 |\n| 2020-11-28 | 2 | 30 |\n| 2020-12-03 | 1 | 41 |\n| 2020-12-09 | 2 | 27 |\n+------------+--------+------------+\n<strong>解释:</strong>\n雇员 1 有三次进出: 有两次发生在 2020-11-28 花费的时间为 (32 - 4) + (200 - 55) = 173, 有一次发生在 2020-12-03 花费的时间为 (42 - 1) = 41。\n雇员 2 有两次进出: 有一次发生在 2020-11-28 花费的时间为 (33 - 3) = 30, 有一次发生在 2020-12-09 花费的时间为 (74 - 47) = 27。\n</pre>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Easy",
|
||
"likes": 46,
|
||
"dislikes": 0,
|
||
"isLiked": null,
|
||
"similarQuestions": "[]",
|
||
"contributors": [],
|
||
"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}",
|
||
"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"
|
||
},
|
||
{
|
||
"lang": "Pandas",
|
||
"langSlug": "pythondata",
|
||
"code": "import pandas as pd\n\ndef total_time(employees: pd.DataFrame) -> pd.DataFrame:\n ",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PostgreSQL",
|
||
"langSlug": "postgresql",
|
||
"code": "-- Write your PostgreSQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"36.8K\", \"totalSubmission\": \"43.7K\", \"totalAcceptedRaw\": 36763, \"totalSubmissionRaw\": 43679, \"acRate\": \"84.2%\"}",
|
||
"hints": [],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "{\"headers\":{\"Employees\":[\"emp_id\",\"event_day\",\"in_time\",\"out_time\"]},\"rows\":{\"Employees\":[[\"1\",\"2020-11-28\",\"4\",\"32\"],[\"1\",\"2020-11-28\",\"55\",\"200\"],[\"1\",\"2020-12-3\",\"1\",\"42\"],[\"2\",\"2020-11-28\",\"3\",\"33\"],[\"2\",\"2020-12-9\",\"47\",\"74\"]]}}",
|
||
"metaData": "{\"mysql\":[\"Create table If Not Exists Employees(emp_id int, event_day date, in_time int, out_time int)\"],\"mssql\":[\"Create table Employees(emp_id int, event_day date, in_time int, out_time int)\"],\"oraclesql\":[\"Create table Employees(emp_id int, event_day date, in_time int, out_time int)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"total_time\",\"pythondata\":[\"Employees = pd.DataFrame([], columns=['emp_id', 'event_day', 'in_time', 'out_time']).astype({'emp_id':'Int64', 'event_day':'datetime64[ns]', 'in_time':'Int64', 'out_time':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Employees(emp_id int, event_day date, in_time int, out_time int)\"],\"database_schema\":{\"Employees\":{\"emp_id\":\"INT\",\"event_day\":\"DATE\",\"in_time\":\"INT\",\"out_time\":\"INT\"}}}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [
|
||
"Create table If Not Exists Employees(emp_id int, event_day date, in_time int, out_time int)",
|
||
"Truncate table Employees",
|
||
"insert into Employees (emp_id, event_day, in_time, out_time) values ('1', '2020-11-28', '4', '32')",
|
||
"insert into Employees (emp_id, event_day, in_time, out_time) values ('1', '2020-11-28', '55', '200')",
|
||
"insert into Employees (emp_id, event_day, in_time, out_time) values ('1', '2020-12-3', '1', '42')",
|
||
"insert into Employees (emp_id, event_day, in_time, out_time) values ('2', '2020-11-28', '3', '33')",
|
||
"insert into Employees (emp_id, event_day, in_time, out_time) values ('2', '2020-12-9', '47', '74')"
|
||
],
|
||
"enableRunCode": true,
|
||
"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>\"]}",
|
||
"book": null,
|
||
"isSubscribed": false,
|
||
"isDailyQuestion": false,
|
||
"dailyRecordStatus": null,
|
||
"editorType": "CKEDITOR",
|
||
"ugcQuestionId": null,
|
||
"style": "LEETCODE",
|
||
"exampleTestcases": "{\"headers\":{\"Employees\":[\"emp_id\",\"event_day\",\"in_time\",\"out_time\"]},\"rows\":{\"Employees\":[[\"1\",\"2020-11-28\",\"4\",\"32\"],[\"1\",\"2020-11-28\",\"55\",\"200\"],[\"1\",\"2020-12-3\",\"1\",\"42\"],[\"2\",\"2020-11-28\",\"3\",\"33\"],[\"2\",\"2020-12-9\",\"47\",\"74\"]]}}",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |