Syntax
BIT_OR(expr) OVER (analytic_clause)
Purpose
BIT_OR() returns the bitwise OR of all bits in expr.
The result is a binary string or a number. This depends on the type of the argument value. When the argument value contains a binary string and the argument is not a hexadecimal, bit, or NULL literal, a binary string result is calculated. Otherwise, a numeric result is calculated. If necessary, the function converts the argument value to an unsigned 64-bit integer.
If no matching row is found, BIT_OR() returns a neutral value, all bits of which are set to 0. The neutral value has the same length as the argument value. NULL has no effect on the result unless all values are NULL. In this case, the result is a neutral value that has the same length as the argument value.
Examples
CREATE TABLE tbl1 (year YEAR (4), month INT(2) UNSIGNED ZEROFILL, day INT(2) UNSIGNED ZEROFILL);
INSERT INTO tbl1 VALUES(2021,1,1),(2021,1,22),(2021,1,3),(2021,2,2), (2021,2,23),(2021,2,23);
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_OR(day) OVER (PARTITION BY year, month) AS days FROM tbl1;
+------+-------+------+
| year | month | days |
+------+-------+------+
| 2021 | 01 | 23 |
| 2021 | 01 | 23 |
| 2021 | 01 | 23 |
| 2021 | 02 | 23 |
| 2021 | 02 | 23 |
| 2021 | 02 | 23 |
+------+-------+------+
6 rows in set