Data Manipulation Functions / Using Aggregate Functions

/* Available in MySQL and PostgreSQL */
SELECT
    CountryCode,
    BIT_AND(Population) and_population,
    BIT_OR(Population) or_population,
    BIT_XOR(Population) xor_population
FROM city
GROUP BY CountryCode


CountryCode and_population or_population xor_population
ABW 29,034 29,034 29,034
AFG 288 1,834,940 1,809,428
AGO 16,384 2,097,148 1,926,184
AIA 577 979 402
ALB 270,000 270,000 270,000
AND 21,189 21,189 21,189
ANT 2345 2345 2345
ARE 0 1,048,575 659,116
ARG 0 4,194,303 2,728,625
...

MySQL BIT_AND() function is an aggregate function that performs a bitwise AND operation of all bits in a column of a table. If both bits are 1, the result is 1; otherwise, the result is 0.
BIT_OR() function is an aggregate function that performs a bitwise OR operation of all bits in a column of a table. It returns 0 if both bits are 0, otherwise it returns 1.
BIT_XOR() function is an aggregate function that performs a bitwise XOR operation of all bits in a column of a table. It returns 1 if only one of the bits is 1 and 0 if both bits are 0 or both bits are 1.