借助 make_set() 函数,我们可以以整数偏移量列表的形式获取 mysql set 列值。为了便于理解,我们创建一个名为“set_testing”的表,如下所示 -
mysql> create table set_testing( id int unsigned not null primary key auto_increment, table set('abc','abd','ghf') not null);query ok, 0 rows affected (0.08 sec)mysql> insert into set_testing (table) values('1');query ok, 1 row affected (0.06 sec)mysql> insert into set_testing (table) values('2');query ok, 1 row affected (0.06 sec)mysql> insert into set_testing (table) values('3');query ok, 1 row affected (0.02 sec)mysql> insert into set_testing (table) values('4');query ok, 1 row affected (0.02 sec)mysql> select * from set_testing;+----+---------+| id | table |+----+---------+| 1 | abc || 2 | abd || 3 | abc,abd || 4 | ghf |+----+---------+4 rows in set (0.00 sec)
现在,以下查询将获取 mysql set 列作为整数偏移量列表 -
mysql> select make_set(types+0,'1','2','3') as output from doctypes1;+--------+| output |+--------+| 1 || 2 || 1,2 || 3 |+--------+4 rows in set (0.00 sec)
以上就是我们如何获取 mysql set 列作为整数偏移量列表?的详细内容。