SQL
Lab
Spotify Spotify Interview Question 10

Long
Listening
Sessions

Find sessions where total listening time exceeds 1 hour.

Table Schema

Inspect
Table

interactive
ColumnType
session_idinteger
user_idinteger
total_duration_secondsinteger

Sample Data

Input
Output

Sample Input: sessions
session_iduser_idtotal_duration_seconds
11011800
21024000
31032000
41045000
51051000
Expected Output
session_id
2
4

SQL Editor

Run
Query

postgresql
Waiting for query

session_id
2
4

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT session_id
FROM sessions
WHERE total_duration_seconds > 3600;

Explanation

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving