Total Time Spent by Each Employee

2pts
Slack

Problem Statement

Slack HR wants to track office utilization. Employees may enter and leave the office multiple times in a single day. You need to calculate the total time each employee spends in the office for each day they were present.

Write an SQL query to calculate the total time in minutes spent by each employee on each day at the office.

Rules:

  • The total time spent on a day is the sum of (out_time - in_time) for all entries of that employee on that day.
  • Return the result table with columns day, emp_id, and total_time.
  • Results must be sorted by day and emp_id in ascending order.
Tests your understanding of
Basic SQL, Aggregation, Math and Grouping

Input Tables

employees
emp_id(INTEGER)event_day(DATE)in_time(INTEGER)out_time(INTEGER)
12020-11-28432
12020-11-2855200
12020-12-03142
22020-11-28333
22020-12-094774

Expected Output

day(DATE)emp_id(INTEGER)total_time(INTEGER)
2020-11-281173
2020-11-28230
2020-12-03141
2020-12-09227

Tags

EasyBasic SQLAggregationMathGrouping
5-10 min
90%

Hints