โ† All SQL Flashcard Decks

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
  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Aggregate Functions and Grouping Flashcards โ€” SQL Study Cards with Answers