Reviewed by Aditya Kumar · Last reviewed 2026-03-24
SELECT * FROM (SELECT region, product_id, SUM(quantity) AS qty, ROW_NUMBER() OVER (PARTITION BY region ORDER BY SUM(quantity) DESC) AS rn FROM sales WHERE sale_date >= CURRENT_DATE - 30 GROUP BY region, product_id) WHERE rn <= 3. **Why**: Filter by date; group by region,...
SELECT * FROM (SELECT region, product_id, SUM(quantity) AS qty, ROW_NUMBER() OVER (PARTITION BY region ORDER BY SUM(quantity) DESC) AS rn FROM sales WHERE sale_date >= CURRENT_DATE - 30 GROUP BY region, product_id) WHERE rn <= 3. Why: Filter by date; group by region, product; rank; top 3. Scalability: Partition pruning on sale_date; index on (region, product_id).
Red Flag: No date filter—full table scan. Pro-Move: 'Partition by sale_date; incremental for last 30 days.'
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.