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.

EasyTechnical
0 practiced
Write SQL to return the top 10 products by total sales value for the current year using sales(product_id, order_id, amount, sold_at). Include product_id, total_sales and rank in the result. Discuss whether you would use ORDER BY + LIMIT or a window function for a dashboard that displays Top-N and the trade-offs between the two approaches.
MediumTechnical
0 practiced
Write a query that computes daily revenue broken down by region and product_category for the last 90 days. Table schema: sales(order_id, sold_at date, region varchar, product_category varchar, amount decimal). Return columns: sold_date, region, product_category, total_revenue. Explain how grouping by multiple columns helps BI filtering and suggest strategies to reduce cardinality for interactive dashboards.
EasyTechnical
0 practiced
Explain the difference between WHERE and HAVING clauses in SQL, specifically in the BI context. Provide a short example using a sales table (product_id, sale_amount) to find products with more than 100 sales and explain why WHERE cannot filter on the aggregated count directly and why HAVING is required.
MediumTechnical
0 practiced
Describe how parameterized filters in BI tools such as Tableau, Looker and Power BI affect aggregated SQL queries. Explain the difference between applying filters at the data source versus client-side, how passing a product category parameter into aggregated queries changes load, and best practices to keep dashboards responsive while supporting dynamic user filters.
HardTechnical
0 practiced
Power BI supports incremental refresh that can speed up queries over large fact tables. Describe how to set up incremental refresh for a daily sales aggregates table: define partitioning strategy, incremental refresh policy, full vs partial refresh, ETL steps to populate partitions, validation tests post-refresh, and risk mitigation for late-arriving data.

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.