Find Total Time Spent

ASKED IN INTERVIEW
2pts
Slack

Problem Statement

Slack office management tracks employee attendance through an automated badge system. Each time an employee enters or leaves the workspace, a log entry is created recording the event day, the employee ID, and the specific hour of entry or exit.

Your task is to calculate the total time (in minutes or hours as per the integers) spent by each employee in the office for each unique day.

Rules:

  • The total time spent is calculated by subtracting the entry time from the exit time for each record.
  • Output columns: day, emp_id, total_time.
  • Results must be sorted by day in ascending order, and then by emp_id in ascending order.
Tests your understanding of
Arithmetic, Aggregation and Grouping

Input Tables

employees_log
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
office_locations
office_id(INTEGER)office_name(VARCHAR)
1San Francisco
2Vancouver
3Dublin
emp_departments
emp_id(INTEGER)dept_name(VARCHAR)
1Engineering
2Product
3Design

Expected Output

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

Tags

EasyASKED IN INTERVIEWArithmeticAggregationGrouping
10-15 min
92%

Hints