Skip to main content

Chapter 9 · Interview Level

Interview-Level SQL Practice

These are the questions you'd get in a data analyst or analytics engineer interview: open business problems where you choose the approach, not drills on a single keyword.

Each one mixes the earlier topics. Read the question twice, state your assumptions, then build the query step by step. That's exactly what interviewers want to see.

Start practising62 exercises · 12 easy, 17 medium, 33 hard

Key ideas

Clarify first
Which statuses count? How are ties handled? What date range?
Build in steps
Use CTEs to go from raw tables to the final answer one step at a time.
Check edge cases
Customers with no orders, NULLs, duplicates and ties.
Read your result
Does the number make sense? Interviewers love candidates who sanity-check.

Example: Customers who ordered in 2024 but not in 2025

SELECT c.id, c.first_name, c.last_name
FROM customers c
WHERE EXISTS (
    SELECT 1 FROM orders o
    WHERE o.customer_id = c.id AND o.order_date LIKE '2024%')
  AND NOT EXISTS (
    SELECT 1 FROM orders o
    WHERE o.customer_id = c.id AND o.order_date LIKE '2025%');

A typical churn question: EXISTS finds last year's buyers and NOT EXISTS removes anyone who came back.

In interviews

Talk while you write. A correct query with clear reasoning beats a clever one-liner you can't explain.

All 62 Interview Level exercises

Ordered from easiest to hardest. Each one runs on a real database with instant feedback.