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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
SQL Table Query With Filters and Aggregates
00:00
5 left

SQL Table Query With Filters and Aggregates

EasySQL · PostgreSQL

Problem

The Roku analytics team wants a quick view of viewing activity on The Roku Channel during January 2025. Write a PostgreSQL query that filters viewing events to the requested date range and summarizes engagement by content category.

Requirements

  1. Include events from January 1, 2025 through January 31, 2025, excluding events on February 1 or earlier dates.
  2. Return one row per content_category with the number of viewing events, total minutes watched, and average minutes watched.
  3. Sort by total minutes watched descending, then by category name ascending for ties.

Output details

  • Use roku_viewing_events as the source table.
  • Return columns in this order: content_category, viewing_events, total_minutes, average_minutes.
  • Alias the output columns exactly as viewing_events, total_minutes, and average_minutes.
  • Count every event row, while SUM and AVG ignore NULL minutes_watched values.
  • Return average_minutes without rounding, preserving PostgreSQL numeric precision.

Schema

roku_viewing_events
ColumnTypeDescription
event_idPKINTEGERUnique viewing event identifier
content_categoryVARCHAR(40)Roku Channel content category
event_dateDATEDate of the viewing event
minutes_watchedINTEGERMinutes watched during the event
Tablesroku_viewing_events
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the one table are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.