SQL Case Study: Answer a Business Question End to End

A dashboard can say β€œsales are down,” but it cannot tell you whether the problem is traffic, conversion, payment failure, stockouts, cancellations or repeat behavior. A weak analyst writes a query; a strong analyst turns that messy business question into a defensible decision.

  • Never start with SQL syntax. Start with the decision, metric, grain, population and time window.
  • An end-to-end SQL answer has six moves: clarify, define metric, map tables, write modular query, validate, recommend.
  • Grain is the level of one row - order, customer-day, product-month or city-week. Wrong grain creates double counting.
  • Use WITH CTEs to make your logic readable: base data, filters, joins, aggregation, final output.
  • Always test edge cases: cancelled orders, null values, duplicate rows, time zones, first-time vs repeat users.
  • A good SQL case answer ends with a business sentence: β€œThe drop is mainly from X, supported by Y and Z; I recommend A.”

The Big Picture: SQL Is the Middle, Not the Starting Point

The interviewer is rarely testing whether you remember every SQL keyword. They are testing whether you can convert ambiguity into an analytical path, use SQL to extract evidence, and make a recommendation that a business team can act on.

End-to-end SQL business question flow A five-stage flow from business question to recommendation. Clarify decision Define metric Map tables Query and QA Answer so what If the answer feels weak, revisit the business definition.
The best SQL answers move from business logic to data logic and back to business action.

The End-to-End SQL Case Framework

Use this six-step structure whenever you get a business question such as β€œWhy did revenue drop?”, β€œWhich users should we target?”, or β€œDid the campaign improve repeat purchases?”

The Difference Between a Query-Only Answer and a Business-Ready Answer

Many candidates can write a GROUP BY. Fewer candidates can defend why that grouping answers the business question. This is the contrast interviewers listen for.

Query-only versus business-ready SQL answer A two-sided comparison of weak and strong SQL case answers. Query-only answer Business-ready answer Starts with syntax Starts with decision β€œSELECT revenue by city” β€œFind the driver of drop” May double-count joins Controls grain first Ends with output table Ends with recommendation Insight is the product
SQL gets you the evidence; business framing makes the evidence useful.

Core SQL Logic: The Order Your Brain Should Follow

SQL is written in one order but logically processed in another. For case interviews, think in the logical order: first build the dataset, then filter it, then aggregate it, then present the answer.

Logical SQL processing order A flow showing the logical order in which SQL clauses are evaluated. FROM JOIN WHERE filter GROUP aggregate HAVING filter agg SELECT present ORDER BY and LIMIT come last
Think in logical processing order to avoid filtering, grouping and join mistakes.

Business Metrics You Should Be Ready to Calculate in SQL

There is no universal β€œgood” conversion rate or repeat rate across categories. In interviews, call this out and benchmark against the right baseline: same weekday, same cohort, same city, same category, or pre-period.

Worked Example: Answer a Before-After Repeat Purchase Question

Business question: β€œDid our February campaign improve repeat purchasing in Bengaluru compared with January?” The correct answer requires a clear metric definition, not just total orders.

Metric definition: Repeat purchase rate = customers with at least 2 delivered orders in the month / customers with at least 1 delivered order in the month.

One clean SQL pattern is to first create customer-month rows, then aggregate them. The exact date function may vary by SQL dialect, but the logic stays the same.

WITH delivered_orders AS (
  SELECT
    order_id,
    customer_id,
    DATE_TRUNC('month', order_date) AS order_month,
    amount
  FROM orders
  WHERE city = 'Bengaluru'
    AND status = 'delivered'
),

customer_month AS (
  SELECT
    order_month,
    customer_id,
    COUNT(*) AS delivered_orders,
    SUM(amount) AS delivered_gmv
  FROM delivered_orders
  GROUP BY order_month, customer_id
)

SELECT
  order_month,
  COUNT(*) AS buyers,
  SUM(CASE WHEN delivered_orders >= 2 THEN 1 ELSE 0 END) AS repeat_buyers,
  ROUND(
    100.0 * SUM(CASE WHEN delivered_orders >= 2 THEN 1 ELSE 0 END)
    / NULLIF(COUNT(*), 0),
    1
  ) AS repeat_purchase_rate_pct,
  SUM(delivered_gmv) AS delivered_gmv
FROM customer_month
GROUP BY order_month
ORDER BY order_month;

Business answer: The campaign did not improve repeat purchase rate in this sample; it stayed at 33.3%. Delivered GMV rose slightly, but the driver was higher value per order, not better repeat behavior. The next cut should segment by acquisition source, discount usage and category to see whether the campaign brought new buyers without improving loyalty.

Definitions You Can Say Clearly

  • SQL: A declarative language used to define, query and manipulate relational data.
  • Business question: A decision-focused question that asks what happened, why it happened, and what to do next.
  • Metric: A quantified measure with a defined numerator, denominator, filters, grain and time window.
  • Grain: The level represented by one row in a dataset or query output.
  • CTE: A named temporary result set created with WITH to make SQL logic modular and readable.
  • Window function: A function that calculates across related rows without collapsing them into one grouped row.

Case Study: Nykaa - Diagnosing a Repeat Commerce Problem

Nykaa’s beauty and fashion marketplace is a strong SQL case because performance depends on demand, assortment, pricing, inventory, delivery and repeat behavior working together.

In beauty commerce, the SQL answer must connect customer behavior with assortment, availability and repeat purchase.
In beauty commerce, the SQL answer must connect customer behavior with assortment, availability and repeat purchase.

Nykaa operates in a category where discovery matters: a shopper may browse skincare, compare shades, wait for discounts, add products to cart, and return only if the product experience and delivery promise are strong. So a question like β€œWhy did repeat revenue fall?” cannot be answered by looking at revenue alone.

Situation: Imagine the growth team sees repeat revenue soften in one category while app traffic remains healthy. A shallow answer would blame marketing immediately. A stronger SQL analyst separates the problem into buyer cohorts, product categories, discount exposure, stock availability, delivery outcomes and cancellations.

The move: The analyst builds a layered SQL analysis: first identifies repeat customers, then joins orders to product category and fulfilment status, then compares cohorts across months. The primary driver must be isolated from supporting drivers. For example, if repeat revenue falls mainly among skincare buyers, the analyst should test whether the cause is lower conversion, lower AOV, out-of-stock items, delayed delivery, lower discounting, or a category-mix shift.

Outcome or lesson: The best answer is not β€œNykaa should give more discounts.” It is: β€œThe repeat revenue dip is chiefly from fewer repeat buyers in a specific category; supporting signals are stock availability and category mix. I would prioritize replenishment and cohort retargeting before increasing blanket discounts.” That is a business answer, not just a SQL output.

How AI Changes Answering a Business Question End to End in SQL

AI will not remove SQL from analytics interviews; it raises the bar. If a tool can draft syntax, the candidate must be better at defining the metric, spotting wrong assumptions and explaining the business implication.

  • Text-to-SQL is becoming normal: Tools can convert β€œshow repeat purchase rate by month” into a draft query, but they often guess joins, grain and filters. Your job is to verify the business definition.
  • AI-assisted data discovery is faster: LLMs can summarize table schemas, suggest likely join keys and identify missing fields. This helps when a case gives multiple tables such as users, orders, payments and events.
  • AI improves QA and anomaly checks: You can ask for edge cases: duplicate order IDs, null customer IDs, cancelled orders, timezone cutoffs, late-arriving events and one-to-many joins.

Use ChatGPT or Claude like a SQL case coach: paste the schema, business question and your metric definition, then ask, β€œFind possible grain mistakes, missing filters and edge cases before writing SQL.” Then write the final query yourself and explain the business recommendation.

Interview Relevance

β€œYou are given tables for users, orders, payments and app events. Revenue dropped last week. How would you investigate the reason using SQL?”

Use the phrase β€œI will define the grain before joining tables.” It signals that you understand the most common source of wrong SQL answers.

Common Mistake

Jumping straight into SQL before defining the metric and grain. This costs candidates because a syntactically correct query can still double-count orders, mix users with sessions, or compare unfair time periods. One-line fix: say, β€œBefore writing SQL, I will define the metric, grain, filters and comparison window.”

What to Revise Next

This is the capstone moment: do one full mock analytics case from scratch. Pick any business question, write the metric tree, sketch the tables, draft the SQL, list QA checks, and end with a recommendation in three sentences.

Mark Lesson Complete (SQL Case Study: Answer a Business Question End to End)