+----+-------------+-----------+
| ID | Work_Option | Work_City |
+----+-------------+-----------+
| 3 | | hangzhou |
+----+-------------+-----------+
1 row in set (0.00 sec)
root@localhost : test 03:10:30> SELECT * FROM mysqlops_set WHERE Work_City=7;
+----+-------------+---------------------------+
| ID | Work_Option | Work_City |
+----+-------------+---------------------------+
| 8 | DBA,SA,NA | shanghai,beijing,hangzhou |
+----+-------------+---------------------------+
1 row in set (0.00 sec)
root@localhost : test 03:13:13> SELECT * FROM mysqlops_set WHERE Work_City=63;
+----+-------------+----------------------------------------------------+
| ID | Work_Option | Work_City |
+----+-------------+----------------------------------------------------+
| 9 | DBA,SA,NA | shanghai,beijing,hangzhou,shenzhen,guangzhou,other |
+----+-------------+----------------------------------------------------+
1 row in set (0.00 sec)
集合类型SET元素的存储顺序梳理:
l 集合类型字段定义的值域列表信息
集合类型值域列表顺序 |
值域列表顺序对应的元素值 |
存储序号二进制编码 |
二进制编码对应的十进制值 |
1 |
shanghai |
0000,0001 |
1 |
2 |
beijing |
0000,0010 |
2 |
3 |
hangzhou |
0000,0100 |
4 |
4 |
shenzhen |
0000,1000 |
8 |
5 |
guangzhou |
0001,0000 |
16 |
6 |
other |
0010,0000 |
32 |
l 集合类型字段存储的值
自增序列字段的值 |
集合类型字段Work_City的值 |
二进制编码 |
十进制值 |
1 |
shanghai |
0000,0001 |
1 |
2 |
空格字符串 |
0000,0000 |
0 |
3 |
hangzhou |
0000,0100 |
4 |
4 |
空格字符串 |
0000,0000 |
0 |
5 |
shanghai |
0000,0001 |
1 |
6 |
shanghai |
0000,0001 |
1 |
7 |
Shanghai,beijing |
0000,0011 |
3 |
8 |
shanghai,beijing,hangzhou |
0000,0111 |
7 |
9 |
shanghai,beijing,hangzhou,shenzhen,guangzhou,other |
0011,1111 |
63 |
10 |
空格字符串 |
0000,0000 |
0 |
11 |
shanghai |
0000,0001 |
1 |
12 |
shanghai |
0000,0001 |
1 |
13 |
hangzhou |
0000,0100 |
4 |
20 |
shanghai,beijing |
0000,0011 |
3 |
原文转自:http://blogread.cn/it/article/5114