Skip to content
Quantoros

What are aggregate functions?

SQLLevel: FoundationAggregations Basics

What are aggregate functions?

Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

Aggregate functions operate on a set of rows and return a single value. The main ones:

  • COUNT() — number of rows / non-NULL values
  • SUM() — total
  • AVG() — average (ignores NULLs)
  • MIN() — minimum value
  • MAX() — maximum value
  • STRING_AGG() / GROUP_CONCAT() — concatenate strings (PostgreSQL / MySQL)
  • ARRAY_AGG() — aggregate into array (PostgreSQL)

Source and licence: SQL Interview Questions — Arda Kocadoru · MIT

Related questions