Using Aggregate Functions

Table 6.1 lists SQL’s standard aggregate functions. The important characteristics of the aggregate functions are:

  • In Table 6.1, expr often is a column name, but it also can be a literal, function, or any combination of column names, literals, and functions coupled by operators.

  • SUM() and AVG() work with only numeric data types. MIN() and MAX() work with characters, numeric, and datetime data types. COUNT(expr) and COUNT(*) work with all data types.

  • All aggregate functions except COUNT(*) ignore nulls. (You can use COALESCE() in an aggregate function argument to substitute a value for a null; see “Checking for Nulls with COALESCE()” in Chapter 5.)

  • COUNT(expr) and COUNT(*) never return null but return either a positive integer ...

Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.