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
Rolling Average with Window Functions
00:00
5 left

Rolling Average with Window Functions

EasySQL · PostgreSQL

Problem

Impact Recruitment Group wants to monitor consultant placement activity over time. Write a PostgreSQL query that calculates a three-day rolling average of completed placements for each active consultant from January 1 through January 5, 2025.

Requirements

  1. Include every active consultant for every date in the requested range, including dates with zero completed placements.
  2. Count only placements whose placement_status is completed.
  3. Use a window function partitioned by consultant and ordered by date. The rolling window must include the current date and the two preceding dates.
  4. Return results ordered by consultant ID and activity date, with the rolling average rounded to two decimal places.

Schema

consultants
ColumnTypeDescription
consultant_idPKINTUnique consultant identifier
consultant_nameVARCHAR(100)Consultant's full name
team_nameVARCHAR(100)Recruitment team assignment
employment_statusVARCHAR(20)Consultant employment status
placements
ColumnTypeDescription
placement_idPKINTUnique placement identifier
consultant_idINTConsultant responsible for the placement
placement_dateDATEDate of the placement activity
placement_statusVARCHAR(20)Placement status, such as completed or pending
Tablesconsultantsplacements
Interviewer

Your question is Rolling Average with Window Functions. 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.