Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Top Brands by Spend
00:00
5 left

Top Brands by Spend

MediumSQL · PostgreSQL

Problem

Given a table of user receipt scans, write a query to find the top three brand partners by total spend for each user segment over the last quarter at Fetch.

Assume the last quarter is the completed calendar quarter relative to the current date. Exclude scans that cannot be associated with a user segment or brand partner.

Output

  1. One row per qualifying segment and brand partner, with columns segment, brand_name, total_spend, and segment_rank.
  2. Include no more than three brands per segment, ordered by segment, rank, total spend descending, and brand name ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Fetch user identifier
segmentVARCHAR(50)User segmentation label
receipt_scans
ColumnTypeDescription
scan_idPKINTUnique receipt scan identifier
user_idINTUser who submitted the scan
brand_idINTBrand identified on the receipt
spend_amountDECIMAL(12,2)Purchase amount represented by the scan
scanned_atDATEDate the receipt was scanned
brand_partners
ColumnTypeDescription
brand_idPKINTUnique brand partner identifier
brand_nameVARCHAR(100)Brand partner name
Tablesusersreceipt_scansbrand_partners
Interviewer

Your question is Top Brands by Spend. 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.