Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Streaming Analytics

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL for Streaming Analytics. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Roku analytics needs a monthly view of streaming time for valid Roku profiles during Q2 2020. Write a PostgreSQL query that aggregates session duration for April, May, and June 2020.

Requirements

  1. Join streaming_sessions to roku_profiles so sessions are included only when they belong to a known Roku profile.
  2. Filter sessions from April 1, 2020, inclusive, through July 1, 2020, exclusive.
  3. Group by calendar month, calculate total streaming minutes, treat NULL durations as zero, and round the total to the nearest whole number.
  4. Return one row per month in chronological order, with the columns month and total_streaming_minutes.

Schema

roku_profiles
ColumnTypeDescription
profile_idPKINTUnique Roku profile identifier
profile_nameVARCHAR(100)Profile display name
device_modelVARCHAR(50)Roku device model
streaming_sessions
ColumnTypeDescription
session_idPKINTUnique streaming session identifier
profile_idINTReferences roku_profiles.profile_id
started_atTIMESTAMPSession start timestamp
duration_minutesNUMERIC(10,2)Session duration in minutes
Tablesroku_profilesstreaming_sessions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results