Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for User Behavior

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

Your question is SQL for User Behavior. 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

How would you write a SQL query to answer a business question about user behavior at Paramount? Using the supplied users, viewing_sessions, and titles tables, return users with at least two completed viewing sessions during January 2026.

Output

  1. One row per qualifying user with user_id, display_name, subscription_plan, completed_sessions, total_watch_minutes, distinct_titles, and engagement_level
  2. Include only users with at least two completed sessions in January 2026
  3. Sort by total_watch_minutes descending, then user_id ascending

Schema

users
ColumnTypeDescription
user_idPKINTUnique Paramount+ user identifier
display_nameVARCHAR(100)User display name
subscription_planVARCHAR(30)Current Paramount+ subscription plan
viewing_sessions
ColumnTypeDescription
session_idPKINTUnique viewing session identifier
user_idINTUser associated with the session
title_idINTWatched title identifier
session_startedTIMESTAMPSession start timestamp
session_endedTIMESTAMPSession end timestamp, null for incomplete sessions
watch_minutesINTMinutes watched during the session
titles
ColumnTypeDescription
title_idPKINTUnique Paramount+ title identifier
title_nameVARCHAR(150)Title name
genreVARCHAR(50)Primary title genre
Tablesusersviewing_sessionstitles
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results