Collections:
ANY_VALUE() - Any Value in Group
How to calculate the average value of a field expression in result set groups using the ANY_VALUE() function?
✍: FYIcenter.com
ANY_VALUE(expr) is a MySQL built-in aggregate function that
returns any value of a field expression in result set groups.
For example:
SELECT help_category_id, MAX(Name), ANY_VALUE(Name) FROM mysql.help_topic GROUP BY help_category_id; -- +------------------+-----------------------------------+---------------------+ -- | help_category_id | MAX(Name) | ANY_VALUE(Name) | -- +------------------+-----------------------------------+---------------------+ -- | 1 | HELP_VERSION | HELP_DATE | -- | 2 | YEAR DATA TYPE | AUTO_INCREMENT | -- | 3 | SHUTDOWN | HELP COMMAND | -- | 4 | TRUE | TRUE | -- | 5 | SPATIAL INDEXES | GEOMETRY HIERARCHY | -- ... -- +------------------+-----------------------------------+---------------------+ SELECT help_category_id, MAX(help_topic_id), ANY_VALUE(2*help_topic_id) FROM mysql.help_topic GROUP BY help_category_id; -- +------------------+--------------------+----------------------------+ -- | help_category_id | MAX(help_topic_id) | ANY_VALUE(2*help_topic_id) | -- +------------------+--------------------+----------------------------+ -- | 1 | 1 | 0 | -- | 2 | 39 | 4 | -- | 3 | 675 | 6 | -- | 4 | 5 | 8 | -- | 5 | 44 | 80 | -- ... -- +------------------+--------------------+----------------------------+
Reference information of the ANY_VALUE() function:
ANY_VALUE(expr): any Returns a randomly selected value of expr from each result set group. Arguments, return value and availability: expr: Required. The field expression in result set groups. any: Return value. An any value of the input expression. Available since MySQL 5.7.
⇒ AVG() - Average Value in Group
⇐ MySQL Functions on Aggregation Groups
2023-12-08, 1000🔥, 0💬
Popular Posts:
How To Use SQL*Plus Built-in Timers in Oracle? If you don't have a stopwatch/timer and want to measu...
How AdventureWorksLT tables are related in SQL Server? There are 12 user tables defined in Adventure...
What Happens to Your Transactions When ERROR 1213 Occurred in MySQL? If your transaction receives th...
How To Download Oracle Database 10g XE in Oracle? If you want to download a copy of Oracle Database ...
How To Get a List of All Tables with "sys.tables" View in SQL Server? If you want to see the table y...