Simple Aggregate Functions

The simple aggregate functions are the ones that came with SQL from the beginning. Every product will have them. They are usually fast because optimizers and index structures often store this data for their own use.

Simple aggregate functions first construct a column of values as defined by the parameter. The parameter is usually a single column name, but it can be an expression with scalar functions and calculations. Pretty much the only things that cannot be used as parameters are other aggregate functions (e.g., SUM(AVG(x)) is illegal) and a subquery (e.g., AVG(SELECT col1 FROM SomeTable WHERE …) is illegal). A subquery could return more than one value, so it would not fit into a column and an aggregate function ...

Get Joe Celko's SQL for Smarties, 4th Edition now with O’Reilly online learning.

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