InterviewStack.io LogoInterviewStack.io

Aggregation and Grouping Questions

Covers SQL grouping and aggregation concepts used to summarize data across rows. Key skills include using GROUP BY with aggregate functions such as COUNT, SUM, AVG, MIN, and MAX, counting distinct values, and filtering grouped results with HAVING while understanding the difference between WHERE and HAVING. Candidates should demonstrate correct handling of NULL values in aggregates, grouping by expressions and multiple columns, and writing multi level aggregations using ROLLUP, CUBE, and GROUPING SETS. Also important is knowing when to use subqueries or common table expressions for intermediate aggregation, the difference between aggregate functions and window functions, and how grouping interacts with joins and data types. Interview questions may test correctness of queries, edge cases, performance considerations such as appropriate indexes and query plans, and the ability to transform business questions like who are the top customers or which categories have declining sales into correct aggregated SQL statements.

HardTechnical
28 practiced
Describe a strategy to maintain an aggregated materialized view under concurrent writes where users can insert, update, and delete events. Explain how to keep aggregates correct with eventual consistency, idempotent upserts, and compaction, and how to handle tombstones for deletes. Provide a concrete flow for applying CDC records to an aggregate table.
MediumTechnical
38 practiced
Write a SQL pattern to compute the top customer by revenue within each state, but also return the state's total revenue and the top customer's contribution percentage. Use standard SQL with CTEs and window functions. Table:
sales(customer_id, state, amount)
HardSystem Design
35 practiced
Design a streaming aggregation pipeline to compute daily unique active users (DAU) where events arrive via Kafka and you need exactly-once semantics and handling of late events up to 24 hours. Describe the components (stream processor, state backend, watermarking), windowing strategy, state size concerns, and how you would handle backfills.
EasyTechnical
32 practiced
Given the table:
orders(order_id INT, customer_id INT, order_date DATE)
Write a SQL query to return the first order date and last order date per customer using aggregate functions. Also briefly describe how you would retrieve the entire row corresponding to the first/last order (not just the date) using SQL.
HardTechnical
39 practiced
Events include a JSON array of product_ids purchased in a session:
sessions(session_id INT, user_id INT, products JSON)
Write SQL (for a JSON-capable engine such as Postgres or BigQuery) to explode the array and compute product-level purchase counts across sessions. Address empty arrays and NULL products explicitly and discuss indexing or storage changes to optimize this pattern.

Unlock Full Question Bank

Get access to hundreds of Aggregation and Grouping interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.