โ† 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 GROUPING SETS((a),(b)) produce?

    Answer: Separate aggregations grouped by a and by b

    GROUPING SETS computes multiple independent groupings in one query.

  2. Which clause can use a column alias defined in SELECT in many databases?

    Answer: HAVING

    Some databases allow SELECT aliases in HAVING since it runs after SELECT logically in those engines.

  3. What is returned by AVG over the values 2, 4, NULL, 6?

    Answer: 4

    AVG ignores NULL, so (2+4+6)/3 = 4.

  4. Which is true about ORDER BY in a grouped query?

    Answer: It sorts the final grouped result

    ORDER BY sorts the output after grouping and aggregation are complete.

  5. What does the MIN function return for a group of dates?

    Answer: The earliest date

    MIN returns the smallest value, which for dates is the earliest one.

  6. Which query finds departments whose average salary exceeds 50000?

    Answer: GROUP BY dept HAVING AVG(salary)>50000

    Filtering on an aggregate per group requires HAVING after GROUP BY.

  7. What happens if you use SELECT name, COUNT(*) FROM t without a GROUP BY in strict mode?

    Answer: Raises an error or undefined behavior

    Mixing a non-aggregated column with an aggregate without GROUP BY is invalid in strict SQL.