Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs

Back to Questions

14. Top Viewers

easy
TikTokTikTok
senior

Which users have the highest number of clips watched, and what are their user_name and total_views? Compute total_views as the count of view events in tiktok_fct_views per viewer_id, and return all users tied for the maximum total_views. Order the results by user_name in ascending order.

tiktok_dim_users
Column NameType
user_idint64
user_nameobject
signup_tsobject
countryobject
suspicious_accountint64
tiktok_fct_views
Column NameType
viewer_idint64
creator_idint64
view_tsobject
device_typeobject
viewed_to_completionint64
sound_idint64
has_promotionint64
Expected Output Schema
Column NameType
user_nameobject
total_viewsint64

Constraints

  • Group by viewer_id; count view-event rows.

  • Return all users tied for maximum count.

  • Output user_name, total_views; sort by user_name.

Hint 1

Start by aggregating tiktok_fct_views by viewer_id and counting rows to get total_views.

Hint 2

Compute the maximum total_views, then filter the aggregated results to only those equal to that max (this keeps ties).

Hint 3

Join the filtered viewers to tiktok_dim_users to fetch user_name, then select (user_name, total_views) and sort by user_name ascending.

Roles
Data Scientist
Data Analyst
Data Engineer
Companies
TikTokTikTok
Levels
senior
entry
Tags
SQL
aggregation
group-by
joins
ties
21 people are solving this problem
Python LogoPython Editor
Ln 1, Col 1

Input Arguments

Edit values below to test with custom inputs

You need tolog in/sign upto run or submit