Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Average Channels Per Account
00:00
5 left

Average Channels Per Account

EasySQL · PostgreSQL

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
Interviewer

Your question is Average Channels Per Account. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.