meaning of the Bit_count function
Used to calculate the number of binary numbers that contain 1.
Select Bit_count (10);
Because 10 turns into binary is 1010, so the result is 2.
meaning of the Bit_or function
is to perform or operate on two binary numbers. Such as:
1100 or 0101-------------- 1101
Example of the MySQL website manual, using Bit_or () Bit_count () to subtly filter out duplicate dates:
The following example shows how can I use the bit group functions to calculate the number of days per month a user have V isited a Web page.
CREATE TABLE T1 (Year of year (4), month int (2) UNSIGNED Zerofill, day int (2) UNSIGNED Zerofill), INSERT into T1 VALUES (200 0,1,1), (2000,1,20), (2000,1,30), (2000,2,2), (2000,2,23), (2000,2,23);
The example table contains Year-month-day values representing visits by users to the page. To determine how many different days in each month these visits occur, use this query:
SELECT Year,month,bit_count (Bit_or (1<<day)) as days from T1 GROUP by Year,month;
which returns:
+------+-------+------+| Year | Month | Days |+------+-------+------+| | | 3 | | | | 2 |+------+-------+------+
MySQL bit_or () bit_count () function