Counting and summarizing
◈ 2 cardsCollapse many rows into one number.
One number from many rows
Aggregate functions reduce a whole column to a single value:
COUNT(*)— number of rowsSUM(price),AVG(price)— total / averageMIN(price),MAX(price)— smallest / largest
SELECT COUNT(*) AS books, AVG(price) AS avg_price
FROM books;
Aggregates ignore NULL (except COUNT(*)). They also respect WHERE, so you can summarize a subset.