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
SQL Rolling Average with Windows
00:00
5 left

SQL Rolling Average with Windows

MediumSQL · PostgreSQL

Problem

Business context

Harnham wants to monitor daily applications to its Recruiter Cloud platform and identify whether recent activity is improving compared with the previous week.

Task

Write a PostgreSQL query that joins the daily metric records to the product catalog, calculates a seven-day rolling average of applications, and compares each available day with the rolling average from seven days earlier.

Requirements

  1. Filter to the Harnham Recruiter Cloud product and the applications metric.
  2. Calculate a seven-calendar-day rolling average using the metric date, ignoring NULL metric values through PostgreSQL aggregate behavior.
  3. Use a window function to retrieve the rolling average from seven days earlier.
  4. Return results from 2025-01-08 onward, ordered by metric date, with the percentage change versus the prior week.

Schema

product_catalog
ColumnTypeDescription
product_idPKINTEGERUnique product identifier
product_nameVARCHAR(100)Harnham product name
daily_metrics
ColumnTypeDescription
metric_idPKINTEGERUnique metric record identifier
product_idINTEGERReferences product_catalog.product_id
metric_nameVARCHAR(50)Name of the measured metric
metric_dateDATECalendar date of the measurement
metric_valueNUMERIC(12,2)Metric value, which may be unavailable
Tablesdaily_metricsproduct_catalog
Interviewer

Your question is SQL Rolling Average with Windows. 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.