Aggregate Syntax

The general syntax of the aggregate functions is this:

aggregate_function([DISTINCT] expression)

Since aggregates are functions, they always take an argument. The argument is an expression, and it is enclosed in parentheses. The expression is often a column name, but it can also be a constant, a function, or any combination of column names, constants, and functions connected by arithmetic operators. Figure 5.1 lists the aggregate functions.

Figure 5.1. Aggregate Functions

You can use DISTINCT with any aggregate except COUNT(*). However, note that DISTINCT gives you no advantage with MIN and MAX because the minimum distinct price ...

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.