InterviewStack.io LogoInterviewStack.io

Aggregation Functions and Group By Questions

Fundamentals of aggregation in Structured Query Language covering aggregate functions such as COUNT, SUM, AVG, MIN, and MAX and how to use them to calculate totals, averages, minima, maxima, and row counts. Includes mastery of the GROUP BY clause to group rows by one or more dimensions such as customer, product, region, or time period, and producing metrics like total revenue by month, average order value by product, or count of transactions by date. Covers the HAVING clause for filtering aggregated groups and explains how it differs from WHERE, which filters rows before aggregation. Also addresses related topics commonly tested in interviews and practical problems: grouping by multiple columns, grouping on expressions and date truncation, using DISTINCT inside aggregates, handling NULL values, ordering and limiting grouped results, using aggregates in subqueries or derived tables, and basic performance considerations when aggregating large datasets. Practice examples include calculating monthly revenue, finding customers with more than a threshold number of orders, and identifying top products by sales.

HardTechnical
58 practiced
Describe a safe, idempotent method to nightly update a partitioned daily_summary table when new transactions and late-arriving events require backfills. Consider partition replacement, MERGE/upsert semantics, transactionality, and minimizing locking for large partitions.
HardTechnical
44 practiced
You must compute the top 10 most frequent tokens per product category from customer reviews stored in a database. Outline a scalable approach using SQL where possible, and describe when and how you would move to a dedicated NLP pipeline (tokenization, stopword removal, stemming) in Spark or an ETL job.
MediumTechnical
48 practiced
Using a reviews(review_id, product_id, rating INT, review_date DATE) table, write a SQL query to find products with average rating >= 4 and at least 50 reviews in the last 365 days. Explain why HAVING is needed and how to avoid including NULL ratings.
MediumTechnical
42 practiced
A customer reports two dashboards showing different daily active users (DAU). Plan an investigation to identify whether the discrepancy comes from aggregation logic, timezone handling, event duplication, or filtering. Outline SQL checks and test queries you would run to find the root cause.
MediumTechnical
46 practiced
Given a Postgres table events(id INT, payload JSONB) where payload contains an array of items with keys item_id and price, write SQL to flatten JSON, extract item_id and price, and compute total revenue per item_id. Consider missing keys and types.

Unlock Full Question Bank

Get access to hundreds of Aggregation Functions and Group By interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.