TOPIC 09/2816 MINNOT STARTED

Totals in plain words: count, SUM (add up), AVG (average), MIN (smallest) and MAX (largest)

Learn the five total functions, what each does with missing values, what they return when no row matches, and how to check a total shown on a screen against a trusted count.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: the closing sheet of a market stall. The stall holder counts the sales, adds the money, and notes the smallest and biggest sale. A voided sale is left out of the money. One sheet gives one set of totals for many sales.

Daily List is a to-do list app. Some tasks have minutes filled in. Plan trip does not. Tom checks the average on the screen against a query, including the case where nobody has a task. (SYNTHETIC / TRAINING ONLY: Daily List and the people here are invented.).

What it is: A turns many rows into one value. (Structured Query Language) is the language of that question. A table is a grid. A row is one task. A column is one fact, such as minutes. The five functions here are COUNT, SUM, AVG, MIN and MAX. The neighbour of COUNT(*) is COUNT(minutes). The star counts every row. The column form skips blanks.

Why it matters: An average can ignore Plan trip. That is the . Or a screen can show a blank where Lily should see zero tasks. That blank is the . Tom cannot see either trap from the average alone.

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB The closing sheet of a market stall that skips voided sales.

  1. Run
  2. Blanks
  3. Empty
Closing sheet

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The count of salescount star
The money totalSUM
The average saleAVG
A voided saleA null

WHERE THIS PICTURE STOPS

  • A sheet is written once, but a screen total updates.
  • A stall holder sees a void, but a null is silent.
  • A stall has a few sales, but a table can have millions.

HOOK

Voids are skipped.

TELL A FRIEND

A closing sheet: voids are skipped.

OFTEN MIXED UP WITH NULL: the value that is not a value. That topic explains null. This one shows how null changes each total.

PRACTISE AND KEEP

Sources for this topic — 3 sources
  1. Market practice

    Aggregate functions (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL reference: count star counts rows, count of a column counts rows where it is not null, sum, avg, min and max skip nulls, and all but count return null when no rows are selected (search excerpt, page not opened)

    §9.21 aggregates, NULL and empty input. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: §9.21 aggregates, NULL and empty input. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  2. Market practice

    SELECT command reference (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL select reference: group by makes groups and having filters groups after grouping (search excerpt, page not opened)

    SELECT: WHERE/HAVING/output aliases, functional dependence, NULL ordering and LIMIT. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: SELECT: WHERE/HAVING/output aliases, functional dependence, NULL ordering and LIMIT. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  3. Implementation-specific

    PostgreSQL documentation ↗ — The PostgreSQL Global Development Group · PostgreSQL 18 official manual, opened 2026-11-06: functions-aggregate §9.21. Supports only PostgreSQL behavior; earlier execution evidence remains separately versioned.

    A free, precise, section-numbered description of the SQL a payments practitioner actually writes. Join types and what happens to unmatched rows, GROUP BY and HAVING against WHERE, window functions and the de-duplication and running-total idioms built on them. Transaction isolation levels and the anomalies each permits, index use, and null three-valued logic.

    Used here for the data-and-SQL questions a Payment Operations Analyst, a Production Support Analyst and a Sanctions Screening Analyst are asked. · Checked 2026-08-18

    An implementation, not the standard — which is the point. ISO/IEC 9075-2 is paywalled, and this documents the same constructs in text anybody can open. Its isolation-level chapter attributes to the standard explicitly, so it can carry a standard-level claim as long as the citation says which document it is quoting.

    Cited as market practice rather than an official standard by kind: an engine's manual is authoritative about that engine and is not the obligation. Where a question turns on behaviour PostgreSQL chose rather than behaviour SQL requires, the answer has to say so.

    One correction carried here because it circulates widely: the sentence "The fundamental difference between WHERE and HAVING…", quoted all over the internet as PostgreSQL documentation, is not in the current documentation. It was searched for in the source tree and is not there.

    Read through a mirror, because the publisher's own domain could not be fetched (a reachability gap, not a statement about the publisher). A 403 there is a policy refusal and says nothing about whether the document exists or is reachable elsewhere.

    Anyone on an unrestricted network should open the canonical URL above and confirm the section and page numbers cited against it. Every claim drawn from this entry is written so that it can be checked against a numbered page.

    Read from the postgres/postgres documentation source tree (doc/src/sgml), which the project itself maintains and which carries the section ids the published URLs are derived from — so a cited section id can be checked against the rendered page.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.