Collections:
BIT_OR() - Bitwise OR in Group
How to calculate the Bitwise OR value of a field expression in result set groups using the BIT_OR() function?
✍: FYIcenter.com
BIT_OR(expr) is a MySQL built-in aggregate function that
calculates the Bitwise OR value of a field expression in result set groups.
For example:
SELECT help_category_id, BIN(BIT_OR(help_topic_id)), COUNT(help_topic_id) FROM mysql.help_topic GROUP BY help_category_id; -- +------------------+----------------------------+----------------------+ -- | help_category_id | BIN(BIT_OR(help_topic_id)) | COUNT(help_topic_id) | -- +------------------+----------------------------+----------------------+ -- | 1 | 1 | 2 | -- | 2 | 111111 | 35 | -- | 3 | 1011111111 | 59 | -- | 4 | 101 | 2 | -- | 5 | 101111 | 3 | -- ... -- +------------------+----------------------------+----------------------+ SELECT help_category_id, BIN(help_topic_id) FROM mysql.help_topic WHERE help_category_id = 5; -- +------------------+--------------------+ -- | help_category_id | BIN(help_topic_id) | -- +------------------+--------------------+ -- | 5 | 101000 | -- | 5 | 101011 | -- | 5 | 101100 | -- +------------------+--------------------+
BIT_OR() is also a window function, you can call it with the OVER clause to calculate the bitwise OR value of the given expression in the current window. For example:
SELECT help_topic_id, help_category_id, BIN(BIT_OR(help_topic_id) OVER w) FROM mysql.help_topic WINDOW w AS (PARTITION BY help_category_id); -- +---------------+------------------+-----------------------------------+ -- | help_topic_id | help_category_id | BIN(BIT_OR(help_topic_id) OVER w) | -- +---------------+------------------+-----------------------------------+ -- | 0 | 1 | 1 | -- | 1 | 1 | 1 | -- | 2 | 2 | 111111 | -- | 6 | 2 | 111111 | -- ... -- | 5 | 4 | 101 | -- | 40 | 5 | 101111 | -- | 43 | 5 | 101111 | -- | 44 | 5 | 101111 | -- | 41 | 6 | 101001 | -- | 42 | 7 | 101010 | -- ... -- +---------------+------------------+-----------------------------------+
Reference information of the BIT_OR() function:
BIT_OR(expr): bin Returns the bitwise OR of all bits in expr. If there are no matching rows, BIT_OR() returns a neutral value (all bits set to 0). Arguments, return value and availability: expr: Required. The field expression in result set groups. bin: Return value. The bitwise OR value of the input expression. Available since MySQL 5.7.
⇒ BIT_XOR() - Bitwise XOR in Group
⇐ BIT_AND() - Bitwise AND in Group
2023-11-18, 988🔥, 0💬
Popular Posts:
Where to find SQL Server Transact-SQL language references? You can find SQL Server Transact-SQL lang...
What Is "mysqld" in MySQL? "mysqld" is MySQL server daemon program which runs quietly in background ...
What To Do If the StartDB.bat Failed to Start the XE Instance in Oracle? If StartDB.bat failed to st...
How To Assign Debug Privileges to a User in Oracle? In order to run SQL Developer in debug mode, the...
How To Convert Characters to Numbers in Oracle? You can convert characters to numbers by using the T...