O'Reilly logo

MySQL Pocket Reference, 2nd Edition by George Reese

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

Functions

MySQL provides built-in functions that perform special operations.

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( ), COUNT( ), and SUM( ) allow DISTINCT.

AVG(expression)

Returns the average value of the values in expression (e.g., SELECT AVG(score) FROM tests).

BIT_AND(expression)

Returns the bitwise AND aggregate of all the values in expression (e.g., SELECT BIT_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 OR aggregate of all the values in expression (e.g., SELECT BIT_OR(flags) FROM options). A bit is set in the result if it is set in at least one of the input fields.

BIT_XOR(expression)

Returns the bitwise XOR aggregate of all the values in expression with 64-bit precision.

COUNT(expression)

Returns the number of times expression was not null. COUNT(*) will return the number of rows with some data in the entire table (e.g., SELECT COUNT(*) FROM folders).

GROUP_CONCAT([DISTNCT] expression [ORDER BY {column | expression}] [SEPARATOR sep])

Provides a string that combines in order all the results marked by expression.

MAX(expression)

Returns the largest value in expression (e.g., SELECT MAX (elevation) FROM mountains).

MIN(expression)

Returns the smallest value ...

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