The following table contains a full list of the aggregate functions in MySQL.
Continue readingTag: functions
MySQL GROUPING() Function Explained
In MySQL, the GROUPING()
function allows us to identity which rows have been generated by the WITH ROLLUP
modifier of the GROUP BY
clause.
By default, WITH ROLLUP
outputs NULL
as the value that represents all aggregate values. By this, I mean it doesn’t provide us with a nice easy to read label. It simply outputs NULL
. This makes it more difficult for us to distinguish between normal rows and super aggregate rows that were generated by WITH ROLLUP
.
Overview of the LIST_ADD() Function in MySQL
In MySQL, list_add()
is a system function that adds a value to a comma-separated list of values and returns the result.
So it’s a handy function that allows us to append a value to a list.
Continue readingOverview of the LIST_DROP() Function in MySQL
In MySQL, list_drop()
is a system function that removes a value from a comma-separated list of values and returns the result.
MySQL ANY_VALUE() Function Explained
In MySQL, ANY_VALUE()
is an aggregate function that allows us to include nonaggregated columns in the SELECT
list when using the GROUP BY
clause.
The ANY_VALUE()
function is commonly used to resolve issues that arise when a query includes columns that are not part of the GROUP BY
clause or aggregate functions. It can be useful in scenarios where we want to include descriptive columns in a grouped result set without affecting the grouping behaviour.
10 Functions and Operators that Search JSON Documents in MySQL
MySQL provides us with a bunch of functions and operators that allow us to search JSON documents for various things, such as specific values, paths, keys, etc.
Here are seven functions and three operators that search JSON documents in MySQL.
Continue readingUnderstanding the VAR_SAMP() Function in MySQL
In MySQL, the VAR_SAMP()
function returns the sample variance of an expression. The denominator is the number of rows minus one.
If there are no matching rows, or if the expression is NULL
, VAR_SAMP()
returns NULL
.
VAR_SAMP()
is an aggregate function, and so it can be used with the GROUP BY
clause.
The VAR_SAMP()
function can also be used as a window function.
How VARIANCE() Works in MySQL
In MySQL, the VARIANCE()
function returns the population standard variance of an expression.
If there are no matching rows, or if the expression is NULL
, the function returns NULL
.
The VARIANCE()
function is a synonym for the standard SQL VAR_POP()
function. In other words, they both do the same thing, but VARIANCE()
is not standard SQL. Therefore, if you need to use standard SQL, use VAR_POP()
instead.
Understanding the VAR_POP() Function in MySQL
In MySQL, the VAR_POP()
function returns the population standard variance of an expression.
If there are no matching rows, or if the expression is NULL
, VAR_POP()
it returns NULL
.
VAR_POP()
is an aggregate function, and so it can be used with the GROUP BY
clause.
The VAR_POP()
function is standard SQL. There’s also a VARIANCE()
function that does the same thing, but is not standard SQL.
Understanding the STDDEV_SAMP() Function in MySQL
In MySQL, the STDDEV_SAMP()
function returns the sample standard deviation of a given expression. This is the square root of VAR_SAMP()
.
STDDEV_SAMP()
is an aggregate function, and so it can be used with the GROUP BY
clause.
If there are no matching rows, or if the expression is NULL
, STDDEV_SAMP()
returns NULL
.