BOOL_OR 函数

bool_or([distinct] expr)

功能描述

BOOL_OR 函数用于判断一组布尔值中是否存在 true。当输入的数据集中至少有一个 true 时,函数返回 true;如果所有值都是 false 或 null,则返回 false。若不设置 distinct 参数,函数将计算所有值;设置 distinct 后,将计算去重后的值。

参数说明

  • expr (boolean 类型): 需要进行逻辑或运算的布尔表达式。

返回类型

  • 返回值类型为 boolean。当存在至少一个 true 值时,返回 true;否则返回 false。
  • 如果输入数据全部为 null,则返回 null。

使用示例

  1. 存在至少一个 true 值时返回 true:
SELECT bool_or(col) FROM VALUES (true), (true), (null) AS tab(col);
+--------------+
| bool_or(col) |
+--------------+
| true         |
+--------------+
  1. 所有值都为 false 或 null 时返回 false:
SELECT bool_or(col) FROM VALUES (false), (false), (null) AS tab(col);
+--------------+
| bool_or(col) |
+--------------+
| false        |
+--------------+
  1. 使用 DISTINCT 参数进行去重后计算:
SELECT bool_or(DISTINCT col) FROM VALUES (true), (true), (null) AS tab(col);
+-----------------------+
| bool_or(DISTINCT col) |
+-----------------------+
| true                  |
+-----------------------+
  1. 多个 false 值和 null 值的情况:
SELECT bool_or(col) FROM VALUES (false), (null), (null) AS tab(col);
+--------------+
| bool_or(col) |
+--------------+
| false        |
+--------------+
  1. 混合值的情况:
SELECT bool_or(col) FROM VALUES (true), (false), (null), (true) AS tab(col);
+--------------+
| bool_or(col) |
+--------------+
| true         |
+--------------+

联系我们
预约咨询
微信咨询
电话咨询