Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL: Median Session Duration
00:00
5 left

SQL: Median Session Duration

MediumSQL · PostgreSQL

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
Interviewer

Your question is SQL: Median Session Duration. Start with the requirements and the two 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.