Counts the number of set bits in the binary representation of value.
Syntax
BIGINT BIT_COUNT(BIGINT|INT|SMALLINT|TINYINT|BOOLEAN value)Parameters
value: Required. A value of the BIGINT, INT, SMALLINT, TINYINT, or BOOLEAN type.
Return value
A value of the BIGINT type is returned. The return value depends on the following rules:
An error is returned if the value parameter is not of the BIGINT, INT, SMALLINT, TINYINT, or BOOLEAN type.
An error is returned if the value parameter is NULL.
Examples
-- Returns 2.
SELECT BIT_COUNT(5);
-- Returns 15.
SELECT BIT_COUNT(32767S);
-- Returns 2.
SELECT BIT_COUNT(-127Y);
-- Returns 1.
SELECT BIT_COUNT(true);
-- Returns 0.
SELECT BIT_COUNT(false);
-- Returns NULL when the value column is NULL.
SELECT BIT_COUNT(value) FROM
VALUES (0), (1), (2), (3), (NULL) AS TAB(value);
-- Result.
+------------+
| _c0 |
+------------+
| 0 |
| 1 |
| 1 |
| 2 |
| NULL |
+------------+