COUNT, SUM, AVG, MIN, MAX
An aggregate turns several input rows into a summary value. Decide what each input row represents before calculating.
COUNT
COUNT(*) counts rows. COUNT(email) counts non-NULL emails. COUNT(DISTINCT customer_id) counts unique non-NULL customer IDs. These answer different questions.
SUM and AVG
SUM adds numeric values; AVG averages non-NULL values. A missing value is skipped, while zero contributes to the average. SUM(sales)/COUNT(*) may differ from AVG(sales) if sales can be missing.
MIN and MAX
MIN and MAX find the smallest and largest non-NULL values. They do not return the other columns from the winning row. To identify the highest order, sort and limit or use a suitable ranking pattern.
Empty inputs and grain
COUNT returns zero for no input rows; many other aggregates return NULL. Summing order-level sales after joining to multiple items can inflate revenue. Count and sum at the correct grain.