Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top N Users During Live Event
00:00
5 left

Top N Users During Live Event

MediumSQL · PostgreSQL

Problem

Business Context

Hotstar wants to identify the most active users during a live sports stream. Activity is measured using watch minutes and engagement actions such as chats and reactions.

Task

Write a PostgreSQL query to return the top 3 active users for the live event with event_id = 101.

Requirements

  1. Include only activity recorded for the specified live event.
  2. Calculate watch minutes, engagement count, and activity_score, where each engagement contributes 5 points.
  3. Rank users by activity score descending, using watch minutes and user ID as tie-breakers.
  4. Return the user rank, user name, watch minutes, engagement count, and activity score.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Hotstar user identifier
display_nameVARCHAR(100)User profile display name
live_events
ColumnTypeDescription
event_idPKINTUnique live event identifier
event_nameVARCHAR(150)Name of the sports event
is_liveBOOLEANWhether the event is currently live
event_activity
ColumnTypeDescription
activity_idPKINTUnique activity record identifier
event_idINTReferenced live event
user_idINTReferenced user, nullable for invalid activity records
activity_typeVARCHAR(20)WATCH, CHAT, or REACTION activity
metric_valueINTWatch minutes, or NULL for engagement activities
Tablesuserslive_eventsevent_activity
Interviewer

Your question is Top N Users During Live Event. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.