Aggregates on Distinct Values

The five aggregate functions can all be used in two ways:

  • To perform calculations on all rows, specify the ALL argument or specify no argument at all (because ALL is the default behavior).

  • To only include unique values, specify the DISTINCT argument.

ALL Is Default The ALL argument need not be specified because it is the default behavior. If DISTINCT is not specified, ALL is assumed.

The following example uses the AVG() function to return the average product price offered by a specific vendor. It is the same SELECT statement used above, but here the DISTINCT argument is used so that the average only takes into account ...

Get Sams Teach Yourself SQL in 10 Minutes, Second Edition 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.