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
Three-Month Sales Decline Query
00:00
5 left

Three-Month Sales Decline Query

MediumSQL · PostgreSQL

Problem

Given a schema containing merchant sales and customer orders, construct a query that identifies merchants who experienced a month-over-month sales decline for three consecutive months.

Use completed customer orders when calculating sales. Treat consecutive months as calendar months with no gaps.

Output

  1. One row per qualifying merchant
  2. Columns: merchant_id and decline_end_month
  3. decline_end_month is the latest month in a qualifying three-month decline sequence
  4. Sort by merchant_id ascending

Schema

merchant_sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
merchant_idINTMerchant associated with the sale
order_idINTCustomer order associated with the sale
sale_dateDATEDate of the sale
sale_amountDECIMAL(12,2)Sale amount
customer_orders
ColumnTypeDescription
order_idPKINTUnique customer order identifier
customer_idVARCHAR(30)Customer who placed the order
order_statusVARCHAR(20)Current order status
Tablesmerchant_salescustomer_orders
Interviewer

Your question is Three-Month Sales Decline Query. 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.