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
7-Day Running Total SQL
00:00
5 left

7-Day Running Total SQL

MediumSQL · PostgreSQL

Problem

Highmark Health analysts need a daily view of enrollment activity to monitor short-term changes across coverage operations. The enrollment source may contain missing dates, so the rolling calculation must use calendar days rather than simply counting the previous seven rows.

Write a PostgreSQL query that calculates the 7-day running enrollment total for January 1 through January 10, 2025.

Requirements

  1. Return enrollment_date, the daily enrollment count, and running_7_day_total.
  2. Include the current date and the six preceding calendar days in each total.
  3. Preserve dates with a NULL daily count, treating them as zero in the total.
  4. Return only the requested January reporting period, ordered chronologically. Enrollment records before January 1 may be used when they fall within a seven-day window.

Schema

daily_enrollments
ColumnTypeDescription
enrollment_datePKDATEDate of enrollment activity
enrollment_countINTEGERNumber of enrollments recorded on the date
Tablesdaily_enrollments
Interviewer

Your question is 7-Day Running Total SQL. Start with the requirements and the one table 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.