BOOL_AND 函数

bool_and([distinct] expr)

功能描述

BOOL_AND 函数用于判断一组布尔值(expr)是否全部为 true。当所有给定的布尔值都为 true 时,函数返回 true;否则,返回 false。如果设置了 distinct 关键字,函数将仅计算不重复的布尔值。

参数说明

  • expr:需要进行逻辑与操作的布尔表达式。

返回类型

布尔值(boolean)。

使用示例

  1. 判断所有布尔值为 true:
SELECT bool_and(col) FROM VALUES (true), (true), (true) AS tab(col);
+---------------+
| bool_and(col) |
+---------------+
| true          |
+---------------+
  1. 包含 null 值的情况:
SELECT bool_and(col) FROM VALUES (true), (true), (null) AS tab(col);
+---------------+
| bool_and(col) |
+---------------+
| true          |
+---------------+
  1. 使用 distinct 关键字,去重后判断所有布尔值为 true:
SELECT bool_and(DISTINCT col) FROM VALUES (true), (true), (true) AS tab(col);
+------------------------+
| bool_and(DISTINCT col) |
+------------------------+
| true                   |
+------------------------+
  1. 包含 false 值的情况:
SELECT bool_and(col) FROM VALUES (false), (true), (null) AS tab(col);
+---------------+
| bool_and(col) |
+---------------+
| false         |
+---------------+
  1. 仅包含一个 true 值和一个 false 值:
SELECT bool_and(col) FROM VALUES (true), (false) AS tab(col);
+---------------+
| bool_and(col) |
+---------------+
| false         |
+---------------+

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