Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Classify Power Users by Activity
00:00
5 left

Classify Power Users by Activity

MediumSQL · PostgreSQL

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
Interviewer

Your question is Classify Power Users by Activity. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.