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: 7-Day Rolling Orders Per Shopper
00:00
5 left

SQL: 7-Day Rolling Orders Per Shopper

MediumSQL · PostgreSQL

Problem

Instacart analyzes shopper workload across fulfillment zones such as North and Central. Write a PostgreSQL query that calculates the seven-day rolling average of completed orders for each shopper and fulfillment zone.

Requirements

  1. Join completed orders to the shopper and fulfillment zone dimensions.
  2. Aggregate completed orders by shopper, zone, and calendar date.
  3. Use a window function partitioned by shopper and zone, with a date-based seven-day frame covering the current date and the prior six days.
  4. Return one row for each shopper-zone-date that has at least one completed order, ordered by shopper, zone, and date.

Schema

shoppers
ColumnTypeDescription
shopper_idPKINTEGERUnique shopper identifier
shopper_nameVARCHAR(100)Shopper display name
home_zone_idINTEGERShopper's assigned home fulfillment zone
fulfillment_zones
ColumnTypeDescription
zone_idPKINTEGERUnique fulfillment zone identifier
zone_nameVARCHAR(100)Fulfillment zone name
orders
ColumnTypeDescription
order_idPKINTEGERUnique order identifier
shopper_idINTEGERAssigned shopper identifier
zone_idINTEGERFulfillment zone identifier
order_dateDATECalendar date of the order
statusVARCHAR(20)Order processing status
Tablesordersshoppersfulfillment_zones
Interviewer

Your question is SQL: 7-Day Rolling Orders Per Shopper. Start with the requirements and the three 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.