Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Channels Per Account

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

Your question is Average Channels Per Account. Start with the requirements and the three 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's streaming analytics team wants to measure channel breadth across accounts. Write a PostgreSQL query that calculates the average number of distinct Roku channels streamed per eligible account during June 2020.

An eligible account is one with at least one June streaming event linked to a valid Roku channel. Do not count duplicate streams of the same channel more than once, and exclude events outside June or events with missing account or channel references.

Requirements

  1. Filter streaming events to the half-open interval from 2020-06-01 00:00:00 through, but not including, 2020-07-01 00:00:00.
  2. Count distinct channels for each eligible account.
  3. Return one value named avg_channels_per_account, rounded to three decimal places.

Schema

roku_accounts
ColumnTypeDescription
account_idPKINTUnique Roku account identifier
account_nameVARCHAR(100)Display label for the account
regionVARCHAR(50)Account's geographic region
roku_channels
ColumnTypeDescription
channel_idPKINTUnique Roku channel identifier
channel_nameVARCHAR(100)Roku channel name
stream_events
ColumnTypeDescription
event_idPKINTUnique streaming event identifier
account_idINTRoku account associated with the event
channel_idINTRoku channel streamed during the event
streamed_atTIMESTAMPTimestamp when streaming occurred
Tablesroku_accountsroku_channelsstream_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results