{
    "data": {
        "question": {
            "questionId": "1892",
            "questionFrontendId": "1741",
            "boundTopicId": null,
            "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 of this table.\nThe table shows the employees&#39; 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 &lt; out_time.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write an SQL query 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 query result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong>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": null,
            "translatedContent": null,
            "isPaidOnly": false,
            "difficulty": "Easy",
            "likes": 77,
            "dislikes": 3,
            "isLiked": null,
            "similarQuestions": "[]",
            "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\"]]}}",
            "categoryTitle": "Database",
            "contributors": [],
            "topicTags": [
                {
                    "name": "Database",
                    "slug": "database",
                    "translatedName": null,
                    "__typename": "TopicTagNode"
                }
            ],
            "companyTagStats": null,
            "codeSnippets": [
                {
                    "lang": "MySQL",
                    "langSlug": "mysql",
                    "code": "# Write your MySQL query statement below\n",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "MS SQL Server",
                    "langSlug": "mssql",
                    "code": "/* Write your T-SQL query statement below */\n",
                    "__typename": "CodeSnippetNode"
                },
                {
                    "lang": "Oracle",
                    "langSlug": "oraclesql",
                    "code": "/* Write your PL/SQL query statement below */\n",
                    "__typename": "CodeSnippetNode"
                }
            ],
            "stats": "{\"totalAccepted\": \"15.9K\", \"totalSubmission\": \"17.4K\", \"totalAcceptedRaw\": 15894, \"totalSubmissionRaw\": 17380, \"acRate\": \"91.4%\"}",
            "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": "{\n  \"mysql\": [\n    \"Create table If Not Exists Employees(emp_id int, event_day date, in_time int, out_time int)\"\n  ],\n  \"mssql\": [\n    \"Create table Employees(emp_id int, event_day date, in_time int, out_time int)\"\n  ],\n  \"oraclesql\": [\n    \"Create table Employees(emp_id int, event_day date, in_time int, out_time int)\",\n    \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n  ],\n  \"database\": true\n}",
            "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,
            "enableTestMode": false,
            "enableDebugger": false,
            "envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
            "libraryUrl": null,
            "adminUrl": null,
            "challengeQuestion": null,
            "__typename": "QuestionNode"
        }
    }
}