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.

HardSystem Design
36 practiced
Design schema and aggregation strategy for a multi-tenant SaaS analytics product that must compute daily active users, revenue, and funnel conversion per tenant. Discuss tenant isolation, storage layout (single table vs per-tenant), sharding heavy tenants, pre-aggregation, query routing, cost allocation, and how to prevent cross-tenant data leakage.
HardTechnical
31 practiced
sessions(session_id, user_id, events jsonb) where events is an array of objects {event_type, value}. Write Postgres SQL to unnest events across all sessions and compute total value per user per event_type. Provide the SQL and discuss indexing strategies or ETL alternatives to avoid expensive jsonb unnest on large historical data.
EasyTechnical
34 practiced
Explain the difference between WHERE and HAVING in SQL. Using a table orders(order_id, customer_id, amount numeric), provide two example SQL queries: one that filters rows with amount > 100 before aggregation and one that filters groups having COUNT(*) > 5 after aggregation. Explain why aggregate functions cannot be used in WHERE and when HAVING is required.
HardTechnical
30 practiced
You have per-shard HyperLogLog sketches for unique users produced by multiple services. Explain how to merge these sketches to produce a global unique user estimate, describe parameter compatibility concerns, discuss error propagation across merges, and suggest storage formats for sketches in a relational database.
MediumTechnical
30 practiced
Given orders(order_id, product_id, amount), write SQL to compute the 90th percentile of order amount per product using Postgres functions (percentile_cont or percentile_disc). Show the query and explain differences between continuous and discrete percentile functions.

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.