Find Total Time Spent by Each Employee
<p>Table: <code>Employees</code></p>

<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| emp_id      | int  |
| event_day   | date |
| in_time     | int  |
| out_time    | int  |
+-------------+------+
(emp_id, event_day, in_time) is the primary key (combinations of columns with unique values) of this table.
The table shows the employees&#39; entries and exits in an office.
event_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.
in_time and out_time are between 1 and 1440.
It is guaranteed that no two events on the same day intersect in time, and in_time &lt; out_time.
</pre>

<p>&nbsp;</p>

<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>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> 
Employees table:
+--------+------------+---------+----------+
| emp_id | event_day  | in_time | out_time |
+--------+------------+---------+----------+
| 1      | 2020-11-28 | 4       | 32       |
| 1      | 2020-11-28 | 55      | 200      |
| 1      | 2020-12-03 | 1       | 42       |
| 2      | 2020-11-28 | 3       | 33       |
| 2      | 2020-12-09 | 47      | 74       |
+--------+------------+---------+----------+
<strong>Output:</strong> 
+------------+--------+------------+
| day        | emp_id | total_time |
+------------+--------+------------+
| 2020-11-28 | 1      | 173        |
| 2020-11-28 | 2      | 30         |
| 2020-12-03 | 1      | 41         |
| 2020-12-09 | 2      | 27         |
+------------+--------+------------+
<strong>Explanation:</strong> 
Employee 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.
Employee 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.
</pre>

[]
['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')"]
[{"value": "mysql", "text": "MySQL", "defaultCode": "# Write your MySQL query statement below\n"}, {"value": "mssql", "text": "MS SQL Server", "defaultCode": "/* Write your T-SQL query statement below */\n"}, {"value": "oraclesql", "text": "Oracle", "defaultCode": "/* Write your PL/SQL query statement below */\n"}, {"value": "pythondata", "text": "Pandas", "defaultCode": "import pandas as pd\n\ndef total_time(employees: pd.DataFrame) -> pd.DataFrame:\n    "}, {"value": "postgresql", "text": "PostgreSQL", "defaultCode": "-- Write your PostgreSQL query statement below\n"}]
{"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"}}}
{"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>"], "pythondata": ["Pandas", "<p>Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4</p>"], "postgresql": ["PostgreSQL", "<p>PostgreSQL 16</p>"]}
['Database']