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 Users and Basket Size
00:00
5 left

Rolling Users and Basket Size

MediumSQL · PostgreSQL

Problem

Instacart's retail partner teams want a daily view of customer activity and basket economics. Write a PostgreSQL query that calculates rolling 7-day active users and average basket size for each retail partner.

Use completed orders from January 1 through January 8, 2024. A rolling 7-day window includes the report date and the six preceding calendar days. Return one row for each partner and date with at least one completed order during the reporting period.

Requirements

  1. Count distinct users with a completed order for the partner within the rolling seven-day calendar window.
  2. Calculate the average basket_amount for completed orders in the same window, rounded to two decimal places. Ignore NULL basket amounts using PostgreSQL aggregate behavior.
  3. Exclude cancelled orders and orders outside the reporting period when determining report dates or contributing metrics.
  4. Sort the output by partner name and report date.

Schema

partners
ColumnTypeDescription
partner_idPKINTEGERUnique retail partner identifier
partner_nameVARCHAR(100)Retail partner name
orders
ColumnTypeDescription
order_idPKINTEGERUnique order identifier
partner_idINTEGERReferences partners.partner_id
user_idINTEGERInstacart customer identifier
order_dateDATEOrder date
statusVARCHAR(20)Order lifecycle status
basket_amountNUMERIC(10,2)Total value of the order basket
Tablespartnersorders
Interviewer

Your question is Rolling Users and Basket Size. 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.