Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Complex SQL With Windows
00:00
5 left

Complex SQL With Windows

HardSQL · PostgreSQL

Problem

Write a complex SQL query to join multiple tables and perform window functions on user activity logs at Roblox.

Return activity events from completed sessions belonging to active users. Include the requested sequence values and exclude events outside their session time range.

Output

  1. One row per qualifying activity event.
  2. Columns: user_id, username, session_id, session_started_at, event_time, event_type, event_value, session_number, and event_number.
  3. Order by user, session start time, event time, and log ID.

Schema

users
ColumnTypeDescription
user_idPKINTRoblox user identifier
usernameVARCHAR(100)Display username
regionVARCHAR(20)User's geographic region
account_statusVARCHAR(20)Current account status
sessions
ColumnTypeDescription
session_idPKINTUnique gameplay session identifier
user_idINTUser who started the session
started_atTIMESTAMPSession start time
ended_atTIMESTAMPSession end time
platformVARCHAR(20)Client platform
session_statusVARCHAR(20)Session completion status
activity_logs
ColumnTypeDescription
log_idPKINTUnique activity event identifier
session_idINTSession associated with the event
event_timeTIMESTAMPTime the activity occurred
event_typeVARCHAR(30)Activity classification
event_valueDECIMAL(10,2)Optional numeric value associated with the event
Tablesuserssessionsactivity_logs
Interviewer

Your question is Complex SQL With Windows. 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.