/* Available in MySQL and PostgreSQL */
SELECT
Name,
CountryCode,
BIT_AND(Population) over p_code and_population,
BIT_OR(Population) over p_code or_population,
BIT_XOR(Population) over p_code xor_population
FROM city
WINDOW p_code AS (partition BY CountryCode)
| Name | CountryCode | and_population | or_population | xor_population |
| Oranjestad | ABW | 29,034 | 29,034 | 29,034 |
| Herat | AFG | 288 | 1,834,940 | 1,809,428 |
| Qandahar | AFG | 288 | 1,834,940 | 1,809,428 |
| Kabul | AFG | 288 | 1,834,940 | 1,809,428 |
| Mazar-e-Sharif | AFG | 288 | 1,834,940 | 1,809,428 |
| Benguela | AGO | 16,384 | 2,097,148 | 1,926,184 |
| Lobito | AGO | 16,384 | 2,097,148 | 1,926,184 |
| Huambo | AGO | 16,384 | 2,097,148 | 1,926,184 |
| Luanda | AGO | 16,384 | 2,097,148 | 1,926,184 |
| ... |
| 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. |