Skip to Main Content
SQL in a Nutshell, 3rd Edition
book

SQL in a Nutshell, 3rd Edition

by Kevin Kline
November 2008
Intermediate to advanced content levelIntermediate to advanced
591 pages
17h 28m
English
O'Reilly Media, Inc.
Content preview from SQL in a Nutshell, 3rd Edition

ANSI SQL Aggregate Functions

Aggregate functions return a single value based upon a set of other values. If used among other expressions in the item list of a SELECT statement, the SELECT must have a GROUP BY or HAVING clause. No GROUP BY or HAVING clause is required if the aggregate function is the only value retrieved by the SELECT statement. The aggregate functions supported by the ANSI SQL standard and their syntax are listed in Table 4-1.

Table 4-1. ANSI SQL aggregate functions

Function

Usage

AVG(expression)

Computes the average value of a column given by expression

CORR(dependent, independent)

Computes a correlation coefficient

COUNT(expression)

Counts the rows defined by the expression

COUNT(*)

Counts all rows in the specified table or view

COVAR_POP(dependent, independent)

Computes population covariance

COVAR_SAMP(dependent, independent)

Computes sample covariance

CUME_DIST(value_list) WITHIN GROUP (ORDER BY sort_list)

Computes the relative rank of a hypothetical row within a group of rows, where the rank is equal to the number of rows less than or equal to the hypothetical row divided by the number of rows in the group

DENSE_RANK(value_list) WITHIN GROUP (ORDER BY sort_list)

Generates a dense rank (no ranks are skipped) for a hypothetical row (value_list) in a group of rows generated by GROUP BY

MIN(expression)

Finds the minimum value in a column given by expression

MAX(expression)

Finds the maximum value in a column given by expression

PERCENT_RANK(value_list) WITHIN GROUP (ORDER BY sort_list ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Effective SQL: 61 Specific Ways to Write Better SQL, First Edition

Effective SQL: 61 Specific Ways to Write Better SQL, First Edition

John L. Viescas, Douglas J. Steele, Ben G. Clothier
SQL in a Nutshell, 4th Edition

SQL in a Nutshell, 4th Edition

Kevin Kline, Regina O. Obe, Leo S. Hsu

Publisher Resources

ISBN: 9780596155322Errata Page