21. min() and max()
The min()
and max()
aggregate functions find the smallest and largest values, respectively, in a column or expression. Some notes about min()
and max()
:
- These functions work with data of most types: numbers, dates, and strings. When a string value is evaluated,
min()
andmax()
will identify the first/last value alphabetically. - These functions will ignore
NULL
values. - Like with other aggregate functions,
min()
andmax()
can accept any valid expression including column references, literal values,case
statements, mathematical expressions, etc.
As an example, let's say we want to find the first and last campaign date for each source code channel. We could do that as follows:
No Results
Page
/
2 10 of 13 records
Exercise 1: Simple min()
and max()
Donor relations wants a summary of each donor's first gift date and last gift date. Write an SQL query using min()
and max()
to generate this data.
No Results
Exercise 2: Complex min()
and max()
Donor relations has a follow-up request. They want you to add two more columns to your output from the previous request:
- Largest Trees fund gift amount
- Smallest Birds fund gift amount
No Results