-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1741. Find Total Time Spent by Each Employee.sql
More file actions
32 lines (26 loc) · 1.24 KB
/
1741. Find Total Time Spent by Each Employee.sql
File metadata and controls
32 lines (26 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Question 1741. Find Total Time Spent by Each Employee
Link: https://leetcode.com/problems/find-total-time-spent-by-each-employee/description/
Table: Employees
+-------------+------+
| 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' 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 < out_time.
Write a solution to calculate the total time in minutes 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 out_time - in_time.
Return the result table in any order.
*/
SELECT
event_day AS day, --noqa: RF04
emp_id,
SUM(out_time - in_time) AS total_time
FROM Employees
GROUP BY event_day, emp_id