Syntax
BIT_OR(expr)
Purpose
Returns the bitwise OR of all bits in expr.
The result type depends on whether the function parameters are evaluated as binary strings or numbers. If the parameter value is a binary string and not a hexadecimal literal, bit literal, or NULL literal, it is evaluated as a binary string. Otherwise, it is evaluated as a number, and the parameter value is converted to an unsigned 64-bit integer when necessary.
If no rows match, BIT_OR() returns a neutral value with the same length as the parameter value (all bits set to 0). NULL values do not affect the result unless all values are NULL, in which case the result is a neutral value with the same length as the parameter value.
Examples
obclient> CREATE TABLE tbl1 (year YEAR (4), month INT(2)UNSIGNED ZEROFILL, day INT(2) UNSIGNED ZEROFILL);
Query OK, 0 rows affected
obclient> INSERT INTO tbl1 VALUES(2021,1,1),(2021,1,22),(2021,1,3),(2021,2,2), (2021,2,23),(2021,2,23);
Query OK, 6 rows affected
Records: 6 Duplicates: 0 Warnings: 0
obclient> SELECT * FROM tbl1;
+------+-------+------+
| year | month | day |
+------+-------+------+
| 2021 | 01 | 01 |
| 2021 | 01 | 22 |
| 2021 | 01 | 03 |
| 2021 | 02 | 02 |
| 2021 | 02 | 23 |
| 2021 | 02 | 23 |
+------+-------+------+
6 rows in set
obclient> SELECT year,month,BIT_COUNT(BIT_OR(1<<day)) AS days FROM tbl1 GROUP BY year,month;
+------+-------+------+
| year | month | days |
+------+-------+------+
| 2021 | 01 | 3 |
| 2021 | 02 | 2 |
+------+-------+------+
2 rows in set
