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
Optimizing Slow SQL or Spark
00:00
5 left

Optimizing Slow SQL or Spark

MediumSQL · PostgreSQL

Problem

Describe a time you had to optimize a slow-running SQL query or Spark job.

Using the provided PostgreSQL tables, rewrite the slow SQL pattern to return the required results efficiently. Explain how you would validate the improvement and identify useful indexes.

Output

  1. One row per active store, including stores with no qualifying transactions.
  2. Columns: store_id, store_name, completed_transaction_count, and completed_revenue.
  3. Include completed transactions from January 1, 2025 through March 31, 2025, sort by revenue descending, then store_id ascending.

Schema

stores
ColumnTypeDescription
store_idPKINTUnique store identifier
store_nameVARCHAR(100)Store display name
regionVARCHAR(50)Geographic region
is_activeBOOLEANWhether the store is currently active
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
store_idINTStore associated with the transaction
transaction_dateDATETransaction date
statusVARCHAR(20)Transaction processing status
amountNUMERIC(10,2)Transaction amount
Tablesstorestransactions
Interviewer

Your question is Optimizing Slow SQL or Spark. 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.