O'Reilly logo

Joe Celko's SQL for Smarties, 4th Edition by Joe Celko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

29

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required