QamoosTech
DatabasesQueryingIntermediateSQLDjango

Aggregation

Pronunciationag-ruh-GAY-shun

Definition

Aggregation combines many rows into a single value, such as a sum, a count, an average, a minimum or a maximum.

Where you hear it

In reporting queries, dashboards, ORM code such as aggregate() and annotate(), and performance reviews.

Examples

  • The report uses an aggregation to total every payment for the week.
  • Let the database do the aggregation instead of looping in Python.
  • The dashboard uses GROUP BY with SUM to show revenue per country.

Common mistake

Fetching every row and adding them up in application code. The database can do it far faster in one query.

Don't confuse with

GROUP BY, which splits rows into groups first so that you get one aggregate per group instead of one for the whole table.

Say it at work

  • In a meeting or chatDo the aggregation in SQL and return just the total.
  • In an email or ticketThat page is slow because it aggregates in Python.