SQLBeginner#aggregates#nulls

What are aggregate functions and how do NULLs affect them?

COUNT, SUM, AVG, MIN and MAX collapse many rows into one value. All of them ignore NULLs; COUNT(*) counts rows while COUNT(col) counts non-NULL values, and AVG divides by the non-NULL count.

Example
-- salaries: 100, NULL, 200
SELECT COUNT(*), COUNT(salary), AVG(salary) FROM employees;
-- 3, 2, 150

Related Questions

1
SQLBeginner#nulls

How do you handle NULL values in SQL?

Open
2
SQLBeginner#functions

What is the difference between COALESCE and CASE?

Open
3
SQLAdvanced#windows

What is a window function?

Open