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 Total Top Three Days
00:00
5 left

Running Total Top Three Days

MediumSQL · PostgreSQL

Problem

Write a query using SQL window functions to calculate the running total revenue per merchant and identify their top 3 highest-grossing days.

Use completed transactions only. Treat NULL revenue as zero when calculating daily revenue, and aggregate multiple transactions for the same merchant and date.

Output

  1. One row per merchant-day included in that merchant's top three days.
  2. Columns: merchant_name, sale_date, daily_revenue, running_total, and top_day_rank.
  3. Rank days by daily revenue descending, breaking ties by date ascending. Order the final result by merchant name and rank.

Schema

merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(100)Merchant display name
merchant_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
merchant_idINTMerchant receiving the transaction
sale_dateDATECalendar date of the transaction
revenueDECIMAL(12,2)Revenue generated by the transaction
statusVARCHAR(20)Transaction processing status
Tablesmerchantsmerchant_transactions
Interviewer

Your question is Running Total Top Three Days. 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.