页次: 1
set 是一种集合类型。 意思是里面可以存储多个值。最多是64个。
下面是一个示例
mysql> create table tb_set ( s set('x', 'y', 'z') ); Query OK, 0 rows affected (0.20 sec) mysql> insert into tb_set values ('x'), ('x,y'), ('x,y,z'); Query OK, 3 rows affected (0.03 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from tb_set; +-------+ | s | +-------+ | x | | x,y | | x,y,z | +-------+ 3 rows in set (0.00 sec) mysql> select * from tb_set where s=1; +------+ | s | +------+ | x | +------+ 1 row in set (0.02 sec) mysql> select * from tb_set where s=2; Empty set (0.00 sec) mysql> select * from tb_set where s=3; +------+ | s | +------+ | x,y | +------+ 1 row in set (0.00 sec) mysql> select * from tb_set where s=4; Empty set (0.00 sec) mysql> select * from tb_set where s=5; Empty set (0.00 sec) mysql> select * from tb_set where s=6; Empty set (0.00 sec) mysql> select * from tb_set where s=7; +-------+ | s | +-------+ | x,y,z | +-------+ 1 row in set (0.00 sec)
通过查询可以发现以下情况
1 对应 x
2 对应 y
3 对应 x和y
4 对应 z
5 对应 x 和 z
了解二进制的就很清楚是怎么个情况了。
1 = 2^0
2 = 2^1
3 = 2^0 + 2^1
ipbbs.net
离线
页次: 1