Skip to content
Tech Interview Prep home
Technical interview guide

Aggregations & GROUP BY

Collapsing many rows into one summary row per group — counts, sums, and averages — plus the HAVING clause that filters groups.

Read
22 min
Practice MCQs
25
Interview QA
25
Edition
v3
Editorial status
Reviewed

Scope: SQL principles with PostgreSQL 18 examples; vendor-specific behavior must be verified.

Interview QA

Treat each question like a live interview question: answer out loud first (structure, assumptions, tradeoffs), then open the model answer to spot gaps and rehearse a tighter follow-up.

Curated: · Written: · Reviewed:

QA-1

Explain the difference between WHERE and HAVING, including when the results differ.

QA-2

How do NULLs affect aggregate results, and where does that cause bugs?

QA-3

A revenue total is too high after a join was added. Diagnose and fix it.

QA-4

Compare GROUP BY with window functions, and give a case needing both.

QA-5

How would you compute several differently-filtered metrics in one query?

QA-6

A grouped query was fast in staging and is slow in production. What do you investigate?

QA-7

Explain grouping sets, ROLLUP and CUBE, and when they earn their complexity.

QA-8

How do you make a financial aggregation reproducible and auditable?

QA-9

When should aggregation be precomputed rather than run on demand?

QA-10

Write a query returning the top three products by revenue within each category.

QA-11

How would you review an aggregation query written by a colleague?

QA-12

Explain COUNT(*), COUNT(column), and COUNT(DISTINCT column) with a case where choosing wrongly matters.

QA-13

How would you build a daily metrics rollup that tolerates late-arriving data?

QA-14

Explain how aggregation is executed, and what that implies for tuning.

QA-15

A stakeholder says two dashboards show different revenue for the same month. How do you investigate?

QA-16

How do you aggregate over a date dimension so that periods with no data still appear?

QA-17

Explain what an ordered-set aggregate such as a percentile does and when to use one.

QA-18

How would you detect and quantify duplicate rows before they corrupt an aggregate?

QA-19

Explain how to compute a running total and a moving average.

QA-20

What are the risks of aggregating directly against a production primary database?

QA-21

How would you aggregate across multiple currencies correctly?

QA-22

Explain what makes an aggregation query testable, and how you would test one.

QA-23

When is it correct to aggregate in the application rather than in the database?

QA-24

Describe how you would design the aggregation layer for a customer-facing analytics feature.

QA-25

Explain the difference between COUNT over a joined result and the count a stakeholder asked for.