Aggregate Functions
SQL · Methods reference
SQL · Methods reference
📋 Overview
Functions collapsing many rows to one value — used with GROUP BY or alone.
🔧 Methods
Common aggregates
| Function | Description |
|---|---|
COUNT(*) / COUNT(col) / COUNT(DISTINCT col) | Row or non-null counts |
SUM(expr) | Numeric total |
AVG(expr) | Mean — NULLs skipped |
MIN(expr) / MAX(expr) | Minimum / maximum |
BOOL_AND / BOOL_OR (PG) | Logical aggregate |
ARRAY_AGG(col) (PG) | Collect to array |
STRING_AGG(col, sep) (PG) | Join strings with separator |
GROUP_CONCAT(col) (MySQL) | Concatenate grouped strings |
💡 Examples
See parent topic notes for runnable snippets; this page is the complete method index.
⚠️ Pitfalls
- Mutating methods return
Nonein Python — do not chainsort()/reverse()expecting a new list. - Default JS
sort()compares strings — pass(a,b) => a-bfor numbers. - SQL function names differ by dialect — verify Postgres vs MySQL docs.
- Django
QuerySet.update()skipssave()signals and autoauto_nowfields on models.