Syntax
BIT_AND(expr)
Purpose
You can call this function to return the bitwise AND 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_AND() returns a neutral value whose all bits are set to 1. The neutral value has the same length as the argument value.
NULL values have 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 product_information(supplier_id INT, product_id INT,list_price numeric, min_price numeric);
INSERT INTO PRODUCT_INFORMATION VALUES ('102050', '1659', '45', NULL);
INSERT INTO PRODUCT_INFORMATION VALUES ('102050', '1770', NULL, '70');
INSERT INTO PRODUCT_INFORMATION VALUES ('102050', '2370', '305', '247');
INSERT INTO PRODUCT_INFORMATION VALUES ('102050', '2380', '750', '731');
INSERT INTO PRODUCT_INFORMATION VALUES ('102050', '3255', NULL, NULL);
INSERT INTO PRODUCT_INFORMATION VALUES ('102050', '1659', '35', NULL);
obclient> SELECT * FROM product_information;
+-------------+------------+------------+-----------+
supplier_id product_id list_price min_price
+-------------+------------+------------+-----------+
102050 1659 45 NULL
102050 1770 NULL 70
102050 2370 305 247
102050 2380 750 731
102050 3255 NULL NULL
102050 2380 750 731
102050 1659 35 NULL
+-------------+------------+------------+-----------+
7 rows in set
obclient> SELECT product_id, BIT_AND(list_price) BITS FROM product_information GROUP BY product_id;
+------------+----------------------+
product_id BITS
+------------+----------------------+
1659 33
1770 18446744073709551615
2370 305
2380 750
3255 18446744073709551615
+------------+----------------------+
5 rows in set