Declaration
ANY(expr)
Description
This function is used to select any value from a set of values, typically in a GROUP BY query. The expr parameter is the column name from which you want to select an arbitrary value. By default, this function ignores NULL values.
Notice
This is a ClickHouse-compatible function. By default, it is not available. To use it, you must set the sql_func_extension_mode parameter to enable it. For more information, see sql_func_extension_mode.
Examples
Enable the ClickHouse extension function mode.
obclient> ALTER SYSTEM SET sql_func_extension_mode = "ClickHouse";Create the test table
test_tbl1.obclient> CREATE TABLE test_tbl1 ( col1 INT AUTO_INCREMENT PRIMARY KEY, col2 INT NOT NULL, col3 DATETIME NOT NULL);Insert data into the
test_tbl1table.obclient> INSERT INTO test_tbl1(col2, col3) VALUES (1, '2026-03-01 10:00:00'), (1, '2026-03-01 11:00:00'), (2, '2026-03-01 12:00:00'), (1, '2026-03-02 10:00:00');Use the
ANYfunction to obtain any access date (col3) for eachcol2.obclient> SELECT col2, ANY(col3) FROM test_tbl1 GROUP BY col2;The return result is as follows:
+------+---------------------+ | col2 | ANY(col3) | +------+---------------------+ | 1 | 2026-03-01 10:00:00 | | 2 | 2026-03-01 12:00:00 | +------+---------------------+ 2 rows in set