Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: Median Session Duration

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

Your question is SQL: Median Session Duration. 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

Write a SQL query to find the median session duration per user segment.

Use the users and sessions tables. Exclude sessions with a NULL duration and users without a segment.

Output

  1. One row per user segment
  2. Columns: segment, median_duration_seconds
  3. Sort alphabetically by segment

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User display name
segmentVARCHAR(50)User segment
sessions
ColumnTypeDescription
session_idPKINTUnique session identifier
user_idINTUser associated with the session
duration_secondsINTSession duration in seconds
Tablesuserssessions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results