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.

MediumTechnical
0 practiced
You're designing a report that requires weekly active users and average revenue per user. Discuss pros and cons of computing these aggregates in ETL/warehouse pre-aggregations versus computing them on-demand in the visualization layer. Include considerations on freshness, query cost, maintainability, and data governance for BI use.
EasyTechnical
0 practiced
In the orders table orders(order_id, customer_id, amount, status), write an SQL query to compute average order amount per customer treating NULL amounts as zero and excluding canceled orders (status = 'canceled'). Explain trade-offs between COALESCE(amount, 0) and filtering NULLs out in averages for BI reporting.
EasyTechnical
0 practiced
Explain the difference between COUNT(*) and COUNT(column) in SQL for BI metrics. Provide examples showing how COUNT(column) treats NULLs differently, and when you should prefer COUNT(DISTINCT column) vs COUNT(*) for metrics such as number of orders versus number of unique customers.
MediumTechnical
0 practiced
Explain how Tableau Level of Detail (LOD) expressions (FIXED, INCLUDE, EXCLUDE) can be used as an alternative to SQL GROUP BY for metrics such as lifetime_spend per customer when the visualization is grouped by region. Provide an example FIXED expression to compute lifetime-spend-per-customer and explain when to prefer LODs versus computing aggregates in ETL or SQL.
HardSystem Design
0 practiced
Design a star schema for a retail analytics warehouse focused on efficient aggregations for BI. Define the fact and dimension tables, the fact grain, surrogate key strategy, handling slowly changing dimensions (SCD Type 2), and explain how this design speeds up GROUP BY queries compared to a highly normalized OLTP schema.

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.