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
Start free
Optimize a Slow SQL Query in Azure
00:00
5 left

Optimize a Slow SQL Query in Azure

MediumSQL · PostgreSQL

Problem

How would you optimize a slow-running SQL query in Azure SQL Database?

Asked in the technical interview stage. Azure Data Engineer, 4-5 yrs exp.

For grading, use customers, orders, order_items, and products. Return completed orders from the first quarter of 2025 for products in the Home Care category, including only customers whose category spend exceeds 100.

Output

  1. One row per qualifying customer.
  2. Columns: customer_id, customer_name, order_count, and total_spend.
  3. Include only completed orders dated from 2025-01-01 through 2025-03-31.
  4. Sort by total_spend descending, then customer_id ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTCustomer identifier
customer_nameVARCHAR(100)Customer display name
regionVARCHAR(50)Customer region
statusVARCHAR(20)Customer account status
orders
ColumnTypeDescription
order_idPKINTOrder identifier
customer_idINTCustomer who placed the order
order_dateDATEDate the order was placed
order_statusVARCHAR(20)Order processing status
order_items
ColumnTypeDescription
order_item_idPKINTOrder line identifier
order_idINTReferenced order
product_idINTReferenced product
quantityINTUnits purchased
unit_priceNUMERIC(10,2)Price per unit
products
ColumnTypeDescription
product_idPKINTProduct identifier
product_nameVARCHAR(100)Product name
categoryVARCHAR(50)Product category
Tablescustomersordersorder_itemsproducts
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the four tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.