Total Time Spent per Day

ASKED IN INTERVIEW
2pts
Slack

Problem Statement

Slack tracks user activity in sessions. You are given a table of activity logs where each entry represents a single session duration in minutes.

Write an SQL query to calculate the total time spent by each user on each day.

Rules:

  • A user can have multiple activity logs on the same day.
  • Output columns: user_id, day, total_minutes.
  • Results must be sorted by user_id in ascending order, then by day in ascending order.
Tests your understanding of
Grouping, Aggregation and Date Conversion

Input Tables

ActivityLogs
log_id(INTEGER)user_id(INTEGER)activity_timestamp(TIMESTAMP)duration_minutes(INTEGER)
112026-02-09 09:00:0030
212026-02-09 14:00:0045
322026-02-09 10:00:00120
412026-02-08 11:00:0020
Users
user_id(INTEGER)user_name(VARCHAR)workspace_id(INTEGER)
1Alice101
2Bob101
Workspaces
workspace_id(INTEGER)workspace_name(VARCHAR)
101Engineering_Dept

Expected Output

user_id(INTEGER)day(DATE)total_minutes(INTEGER)
12026-02-0820
12026-02-0975
22026-02-09120

Tags

EasyASKED IN INTERVIEWGroupingAggregationDate Conversion
10-15 min
76%

Hints