ANY_VALUE
Description
The ANY_VALUE function is useful for GROUP BY queries.
Syntax
1. > ANY_VALUE(arg)
Arguments
| Arguments | Description |
|---|---|
| arg | Any type. When arg is NULL, the line does not participate in the calculation. |
Returned Value
The function return value and type are the same as the return value and type of its argument.
note
The execution result of ANY_VALUE is uncertain. The same input may produce different execution results.
Examples
1. > create table t1(
2. -> a int,
3. -> b int,
4. -> c int
5. -> );
6. > create table t2(
7. -> a int,
8. -> b int,
9. -> c int
10. -> );
11. > insert into t1 values(1,10,34),(2,20,14);
12. > insert into t2 values(1,-10,-45);
13. > select ANY_VALUE(t1.b) from t1 left join t2 on t1.c=t1.b and t1.a=t1.c group by t1.a;
14. +-----------------+
15. | any_value(t1.b) |
16. +-----------------+
17. | 10 |
18. | 20 |
19. +-----------------+
20. 2 rows in set (0.01 sec)
21. > select 3+(5*ANY_VALUE(t1.b)) from t1 left join t2 on t1.c=t1.b and t1.a=t1.c group by t1.a;
22. +---------------------------+
23. | 3 + (5 * any_value(t1.b)) |
24. +---------------------------+
25. | 53 |
26. | 103 |
27. +---------------------------+
28. 2 rows in set (0.00 sec)
