# Aggregate Functions — MySQL

Source: https://www.geekswithgeeks.com/en/mysql/sql-aggregate-functions

> COUNT, SUM, AVG, MIN and MAX summarize a column.

## The five common ones

`COUNT`, `SUM`, `AVG`, `MIN`, `MAX` collapse many rows into a single summary value.

```sql
SELECT COUNT(*) AS total_orders,
       SUM(amount) AS revenue,
       AVG(amount) AS avg_order,
       MAX(amount) AS biggest
FROM orders;
```

Output:

```
total_orders | revenue | avg_order | biggest
3            | 4500.00 | 1500.00   | 2000.00
```

## COUNT(*) vs COUNT(column)

`COUNT(*)` counts all rows; `COUNT(column)` skips rows where that column is `NULL`.

**Quiz:** Which counts only non-NULL values in a column?

- [ ] COUNT(*)
- [x] COUNT(column_name)
- [ ] SUM(column_name)

*Answer:* COUNT(column_name). COUNT(column) ignores NULLs in that column; COUNT(*) counts every row.
