1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
|
DROP TABLE IF EXISTS `test_table`;
CREATE TABLE `test_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`type` enum('First','Second','Third','Last') DEFAULT NULL,
`set` set('First','Second','Third','Last') DEFAULT NULL,
`num1` int(11) NOT NULL DEFAULT 0,
`num2` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
INSERT INTO `test_table` (`id`,`name`,`type`,`set`,`num1`,`num2`) VALUES
(1,'Art 1','First','Last',1,7),
(2,'Art 2','Second','First,Last',3,7),
(3,'Art 3','Second','Second,Last',5,7),
(4,'Art 4','Third','First,Second,Last',5,7),
(5,'Art 5','Last','First,Last',7,15),
(6,'Art 6','First','First,Last',7,15),
(7,'Art 7','Third','First,Third,Last',9,15),
(8,'Art 8','Last','Second,Third,Last',9,15);
select * from `test_table`;
select BIT_XOR(name) from test_table;
select BIT_XOR(num1),BIT_XOR(num2),BIT_XOR(`type`),BIT_XOR(`set`) from test_table;
select BIT_XOR(num1),BIT_XOR(num2),BIT_XOR(`type`),BIT_XOR(`set`) from test_table where `type`='third';
select bin(BIT_XOR(num1)),bin(BIT_XOR(num2)) from test_table where id>8;
/* as Window function */
SELECT name, `type`, num1, BIT_XOR(num2)
OVER (PARTITION BY `type`) AS `bit_xor` FROM test_table;
select BIT_XOR(null), bin(BIT_XOR(null));
|