Aggregate Functions and Grouping Flashcards
7 cards from real SQL practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Aggregate Functions and Grouping flashcards as text
What does GROUP BY ROLLUP(region, product) add to the result set?
Answer: Subtotal and grand total rows
ROLLUP generates subtotals for each level plus a grand total row.
Which query correctly counts employees per department having more than 5 members?
Answer: SELECT dept, COUNT(*) FROM emp GROUP BY dept HAVING COUNT(*)>5
Aggregate filtering on groups requires HAVING after GROUP BY.
What value does SUM return for a group where every row's column is NULL?
Answer: NULL
SUM over all-NULL values returns NULL, not 0.
Which statement about combining aggregate and non-aggregate columns is true in standard SQL?
Answer: Non-aggregated columns must appear in GROUP BY
Every non-aggregated SELECT column must be in the GROUP BY clause.
What does COUNT return when applied to an empty table?
Answer: 0
COUNT returns 0 on an empty set, unlike SUM or AVG which return NULL.
Which aggregate would you use to find the total revenue across all orders?
Answer: SUM(amount)
SUM adds all values together to give the total revenue.
Can you nest aggregate functions like SUM(MAX(x)) directly in a single GROUP BY query?
Answer: No, it is generally not allowed
Nesting aggregates directly is not permitted; you must use a subquery instead.