Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
Window Functions for Rolling Averages
00:00
5 left

Window Functions for Rolling Averages

HardSQL · PostgreSQL

Problem

Dell Technologies uses Dell APEX usage analytics to evaluate engagement across customer signup cohorts. Write a PostgreSQL query that creates a daily user activity series for a fixed reporting period, calculates each user's 7-day rolling average, and ranks users within their cohort for each day.

Requirements

  1. Use 2025-02-01 through 2025-02-05 as the reporting period.
  2. Aggregate multiple usage events for the same user and day. Treat missing or NULL usage as zero.
  3. Include users with no usage events during the reporting period.
  4. Calculate a calendar-based rolling average using the current day and up to the six preceding days.
  5. Rank users within each signup-month cohort and activity date by rolling average descending. Ties must receive the same rank.
  6. Return cohort_month, activity_date, user_id, rolling_avg_units, and cohort_rank, ordered by cohort, date, and rank.

Schema

apex_users
ColumnTypeDescription
user_idPKINTEGERUnique APEX user identifier
signup_dateDATEDate the user joined Dell APEX
regionVARCHAR(30)Customer operating region
apex_usage_events
ColumnTypeDescription
event_idPKINTEGERUnique usage event identifier
user_idINTEGERReferences apex_users.user_id
event_dateDATEDate of the usage event
units_usedINTEGERAPEX capacity units consumed in the event
Tablesapex_usersapex_usage_events
Interviewer

Your question is Window Functions for Rolling Averages. 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.