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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Running Sales Totals by Region
00:00
5 left

Running Sales Totals by Region

MediumSQL · PostgreSQL

Problem

Walmart Marketplace analysts need a regional view of recent sales performance. Using the reporting date of 2025-03-15, write a PostgreSQL query that calculates daily sales and a running 30-day total for each region.

Requirements

  1. Include sales from 2025-02-14 through 2025-03-15, inclusive.
  2. Exclude rows with a missing region.
  3. Aggregate multiple sales records on the same region and date into daily sales.
  4. Use a window function to calculate the cumulative sales total independently for each region, ordered by sale date.

Output details

  • Return columns in this order: region, sale_date, daily_sales, and running_total.
  • Order results by region ascending, then sale_date ascending.
  • Treat NULL sales amounts as 0.00 when calculating daily sales.

Schema

marketplace_sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
regionVARCHAR(50)Walmart Marketplace sales region
sale_dateDATEDate when the sale occurred
sales_amountNUMERIC(12,2)Sale amount in dollars
Tablesmarketplace_sales
Interviewer

Your question is Running Sales Totals by Region. 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.