Aggregate Function. Perform an XOR function on corresponding pairs of bits (i.e., the first pair of bits, the second pair of bits, etc.) SinceBIT_XOR is an aggregate function it can be used with the GROUP BY clause.


BIT_XOR  (<expr1>, <expr2>)


  • expression: expressions must be integer data types.

Return Type

This will result in a one if two of the corresponding bits are different.  If the bits are the same it will return a zero.


CREATE TABLE numeric_sample (group_name varchar(10), ltr_val int);
INSERT INTO numeric_sample VALUES
  ('alpha', 111), ('beta', 110), ('gamma', 000), ('delta', 001);

SELECT group_name, BIT_XOR(001) FROM numeric_sample GROUP BY group_name;
|group_name | BIT_AND(001)|
|alpha      | 1           |
|beta       | 1           |
|delta      | 1           |
|gamma      | 1           |