bool_or
Returns true if at least one row for expr
is true. Otherwise, returns false. boolor_agg
is an alias for this function.
Syntaxβ
bool_or(expr)
Parametersβ
expr
: The expression must evaluate to a boolean value, that is, true or false.
Return valueβ
Returns a boolean value. An error is returned if expr
does not exist.
Usage notesβ
This function ignores NULL values.
Examplesβ
-
Create a table named
employees
.CREATE TABLE IF NOT EXISTS employees (
region_num TINYINT,
id BIGINT,
is_manager BOOLEAN
)
DISTRIBUTED BY HASH(region_num); -
Insert data into
employees
.INSERT INTO employees VALUES
(3,432175, TRUE),
(4,567832, FALSE),
(3,777326, FALSE),
(5,342611, TRUE),
(2,403882, FALSE); -
Query data from
employees
.MySQL > select * from employees;
+------------+--------+------------+
| region_num | id | is_manager |
+------------+--------+------------+
| 3 | 432175 | 1 |
| 4 | 567832 | 0 |
| 3 | 777326 | 0 |
| 5 | 342611 | 1 |
| 2 | 403882 | 0 |
+------------+--------+------------+
5 rows in set (0.01 sec) -
Use this function to check for managers in each region.
Example 1: Check if there is at least one manager in each region.
MySQL > SELECT region_num, bool_or(is_manager) from employees
group by region_num;
+------------+---------------------+
| region_num | bool_or(is_manager) |
+------------+---------------------+
| 3 | 1 |
| 4 | 0 |
| 5 | 1 |
| 2 | 0 |
+------------+---------------------+
4 rows in set (0.01 sec)
keywordβ
BOOL_OR, bool_or, boolor_agg