Reviewed by Aditya Kumar · Last reviewed 2026-03-24
SELECT category, product_id, product_name, sales FROM (SELECT category, product_id, product_name, sales, ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) AS rn FROM products) ranked WHERE rn <= 3. **Why**: Define 'performing' (revenue, units, margin). Consider time...
SELECT category, product_id, product_name, sales FROM (SELECT category, product_id, product_name, sales, ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) AS rn FROM products) ranked WHERE rn <= 3. Why: Define 'performing' (revenue, units, margin). Consider time window (e.g., last 90 days). Scalability: Pre-aggregate in mart for dashboards. Use RANK/DENSE_RANK for ties.
Red Flag: No time window—all-time vs recent. Pro-Move: 'We use last 90 days; RANK for ties; materialized for BI.'
According to DataEngPrep.tech, this is one of the most frequently asked SQL interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.