Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Classify Power Users by Activity

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

Your question is Classify Power Users by Activity. 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

StreamWave wants to segment users by recent activity. Write a PostgreSQL query to identify power users and compare them with casual users over the last 30 days.

A user is a power user if they completed 5 or more sessions in the last 30 days. Otherwise, they are a casual user. Only include users whose account status is active.

Requirements

  1. Count each active user's completed sessions in the last 30 days.
  2. Classify users as power_user or casual_user using the 5-session threshold.
  3. Return one row per segment with:
    • number of users
    • average completed sessions per user
    • average total minutes watched per user
  4. Include active users with zero completed sessions as casual_user.
  5. Order results by user_segment.

Schema

users
ColumnTypeDescription
user_idPKINTPrimary key for each user
user_nameVARCHAR(100)Full name of the user
signup_dateDATEDate the user created the account
statusVARCHAR(20)Account status such as active or inactive
sessions
ColumnTypeDescription
session_idPKINTPrimary key for each session
user_idINTUser who started the session
session_dateDATEDate of the session
duration_minutesINTLength of the session in minutes
session_statusVARCHAR(20)Status of the session such as completed or cancelled
Tablesuserssessions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results