"Strong SQL" sounds vague. In the interview it means 8 specific patterns.
Group and filter, find what's missing, bucket and report by month, rank inside groups, and write it cleanly.
Practise all eight.
1-4: group, join, buckets, dates
- 01
GROUP BY with HAVING
WHERE filters rows. HAVING filters groups.
SELECT city, SUM(amount) AS total FROM orders GROUP BY city HAVING SUM(amount) > 50000; - 02
LEFT JOIN to find what's missing
Customers who never ordered.
SELECT c.name FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id WHERE o.order_id IS NULL; - 03
CASE WHEN buckets
Turn amounts into bands a manager can read.
SELECT order_id, CASE WHEN amount >= 5000 THEN 'High' WHEN amount >= 1000 THEN 'Mid' ELSE 'Low' END AS band FROM orders; - 04
Month-wise numbers (MySQL)
Monthly totals for a report.
SELECT DATE_FORMAT(order_date, '%Y-%m') AS month, SUM(amount) AS total FROM orders GROUP BY month;
5-8: window functions, clean and readable
- 05
Top 3 per group with ROW_NUMBER
Number rows inside each city, keep the first 3.
SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( PARTITION BY city ORDER BY amount DESC) AS rn FROM orders) t WHERE rn <= 3; - 06
Running total
Cumulative sum by date.
SELECT order_date, amount, SUM(amount) OVER ( ORDER BY order_date) AS running FROM orders; - 07
CTEs instead of nested mess
Name the step, then use it.
WITH city_total AS ( SELECT city, SUM(amount) AS t FROM orders GROUP BY city) SELECT * FROM city_total WHERE t > 50000; - 08
Duplicates and NULLs
Find repeats, and stop NULLs breaking totals.
SELECT email, COUNT(*) AS n FROM customers GROUP BY email HAVING COUNT(*) > 1; -- COALESCE(amount, 0) for NULLs
JD line, decoded
| JD says | They test |
|---|---|
| Strong SQL | GROUP BY, HAVING, joins |
| Data extraction | Joins across 3-4 tables |
| Reporting | Month-wise numbers, CASE buckets |
| Advanced SQL | ROW_NUMBER, RANK, LAG |
| Data quality | Duplicates, NULLs |
| Optimised queries | CTEs, filter early |
Practise these on real tables in the free SQL playground, then check your answers against the 8 things interviewers check.