Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Top 10% by Session Length

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

Your question is SQL Top 10% by Session Length. Start with the requirements and the two 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

The Roblox Creator Analytics team wants to identify users with exceptionally high platform engagement. Write a PostgreSQL query that ranks registered Roblox users by their total recorded session length and returns the top 10%.

Requirements

  1. Aggregate all recorded session minutes for each registered user.
  2. Include registered users with no sessions as zero total minutes.
  3. Use a window function to divide users into ten ordered groups, then return the highest group.
  4. Return user_id, username, and total_session_minutes, ordered from highest to lowest total.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Roblox user identifier
usernameVARCHAR(50)Roblox username
platformVARCHAR(20)Primary client platform used by the user
user_sessions
ColumnTypeDescription
session_idPKINTUnique session identifier
user_idINTAssociated Roblox user identifier
session_length_minutesINTSession duration in minutes
Tablesusersuser_sessions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results