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.
- 01Customers with Missing Phone NumbersecommerceEasy
- 02Customer Contact with COALESCE FallbackecommerceEasy
- 03Classify Orders by SizeecommerceEasy
- 04Extract Year from Order DatesecommerceEasy
- 05Uppercase Product NamesecommerceEasy
- 06Combine Cancelled and Returned OrdersecommerceEasy
- 07Customers Who Have Written ReviewsecommerceEasy
- 08Customer Count by StateecommerceEasy
- 09Second Most Expensive ProductecommerceEasy
- 10Patient Contact Info with COALESCEhealthcareEasy
- 11Patient Count by Email DomainhealthcareEasy
- 12Current Patient Age CalculationhealthcareEasy
- 13Each Customer's Most Recent Order AmountecommerceMedium
- 14Average Days to Ship by StatusecommerceMedium
- 15Product Pairs in the Same CategoryecommerceMedium
- 16Orders That Were Never ShippedecommerceMedium
- 17Revenue Pivot by Payment Method Per MonthecommerceMedium
- 18Cumulative Spending Per CustomerecommerceMedium
- 19Top-Selling Category by QuantityecommerceMedium
- 20Each Product's Share of Total RevenueecommerceMedium
- 21Customers Using Multiple Payment MethodsecommerceMedium
- 223-Order Moving Average Per CustomerecommerceMedium
- 23Combined Cash Inflow ReportfinanceMedium
- 24Average Days Between Loan PaymentsfinanceMedium
- 25Prescription Duration in DayshealthcareMedium
- 26Visit Status Summary with CASEhealthcareMedium
- 27Combined Doctor and Patient Contact ListhealthcareMedium
- 28Patients with Visits but No Lab ResultshealthcareMedium
- 29Doctors Who Treated Every Blood TypehealthcareMedium
- 30Revenue Pivot by Payment MethodecommerceHard
- 31Average Delivery Time by CarrierecommerceHard
- 32Top 3 Best-Selling Products Per CategoryecommerceHard
- 33Customer Cohort Analysis by First Purchase MonthecommerceHard
- 34RFM Customer SegmentationecommerceHard
- 35Market Basket: Frequently Co-Purchased ProductsecommerceHard
- 36Monthly Cohort Retention AnalysisecommerceHard
- 37Inventory Reorder Alert with Sales VelocityecommerceHard
- 38Customer Churn Risk ScoringecommerceHard
- 39Deduplicate Reviews with ROW_NUMBERecommerceHard
- 40Compare Each Order to Previous and NextecommerceHard
- 41Assign Customers to Spending QuartilesecommerceHard
- 42Order Date Gap AnalysisecommerceHard
- 43Monthly Cohort Retention RateecommerceHard
- 44Customer Consecutive Order Month StreaksecommerceHard
- 45Refund Rate and Revenue Impact AnalysisecommerceHard
- 46Monthly Deposits vs WithdrawalsfinanceHard
- 47Loan Payment Coverage RatiofinanceHard
- 48Detect Suspicious Transaction PatternsfinanceHard
- 49Transaction Type Pivot by AccountfinanceHard
- 50Loan Risk Classification with CASEfinanceHard
- 51Customers with Both Accounts and Loans (EXISTS)financeHard
- 52Executive Financial Dashboard QueryfinanceHard
- 53Detect Suspicious Large Withdrawal PatternsfinanceHard
- 54Account Cohort Activity AnalysisfinanceHard
- 55Find Duplicate Patient EmailshealthcareHard
- 56Department Budget UtilizationhealthcareHard
- 57Comprehensive Doctor ScorecardhealthcareHard
- 58Follow-Up Visit ChainshealthcareHard
- 59Pivot Visit Counts by Status per DoctorhealthcareHard
- 60Patient Risk CategorizationhealthcareHard
- 61Comprehensive Hospital Performance ReporthealthcareHard
- 62Department Performance DashboardhealthcareHard