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 the GROUPING() function indicate in a ROLLUP query?
Answer: Whether a column is aggregated in a subtotal row
GROUPING() returns 1 when the column is a superaggregate (subtotal) and 0 otherwise.
Which set of columns does GROUP BY CUBE(a, b) aggregate over?
Answer: All combinations: (a,b),(a),(b),()
CUBE generates all possible grouping combinations of the listed columns.
When computing COUNT(DISTINCT a, b) (where supported), what is counted?
Answer: Distinct combinations of a and b
It counts the number of unique pairs of values across columns a and b.
What is the result type of AVG over an integer column in most databases?
Answer: A decimal or floating-point value
AVG typically returns a decimal/float to preserve fractional results.
In a query grouping by year, which is required to also filter on the underlying raw column status='active'?
Answer: WHERE status='active'
Row-level conditions on non-aggregated columns belong in WHERE before grouping.
What does SUM(DISTINCT amount) compute?
Answer: Sum of only the unique amount values
DISTINCT removes duplicate values before summing the unique ones.
Which combination is valid: SELECT dept, MAX(salary) FROM emp GROUP BY dept ORDER BY MAX(salary) DESC?
Answer: Valid: orders departments by their max salary
ORDER BY can reference aggregate expressions to sort grouped output.