ANY_VALUE

函数说明

ANY_VALUE 在范围内任选一个值返回。

函数语法

  1. > ANY_VALUE(arg)

参数释义

参数说明
arg可为任意类型。当 arg 为 NULL 时,该行不参与计算。

返回值

返回类型和输入类型相同。

说明:ANY_VALUE 的执行结果具有不确定性,相同的输入可能得到不同的执行结果。

示例

  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)