Aggregate Functions
Aggregate
functions operate on a set of data. These are usually used to perform
some action on a complete set of returned rows. For example,
SELECT
AVG(height) FROM kids
would return the average of all the values of the
height field in the kids table.
-
AVG(expression) Returns the average value of the values in
expression(e.g.,SELECT AVG(score)FROM tests).-
BIT_AND(expression) Returns the bitwise
ANDaggregate of all the values inexpression(e.g.,SELECTBIT_AND(flags) FROM options). A bit will be set in the result if and only if the bit is set in every input field.-
BIT_OR(expression) Returns the bitwise
ORaggregate of all the values inexpression(e.g.,SELECTBIT_OR(flags) FROM options). A bit is set in the result if it is set in at least one of the input fields.-
COUNT(expression) Returns the number of times
expressionwas not null.COUNT(*)will return the number of rows with some data in the entire table (e.g.,SELECTCOUNT(*)FROMfolders).-
MAX(expression) Returns the largest value in
expression(e.g.,SELECTMAX(elevation)FROM mountains).-
MIN(expression) Returns the smallest value in
expression(e.g.,SELECTMIN(level)FROMtoxic_waste).-
STD(expression)/STDDEV(expression) Returns the standard deviation of the values in
expression(e.g.,SELECTSTDDEV(points) FROM data).-
SUM(expression) Returns the sum of the values in
expression(e.g.,SELECT SUM(calories) FROMdaily_diet).
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.
Read now
Unlock full access