首页  >  文章  >  数据库  >  我们如何获取 MySQL SET 列作为整数偏移量列表?

我们如何获取 MySQL SET 列作为整数偏移量列表?

王林
王林转载
2023-08-25 19:21:031378浏览

我们如何获取 MySQL SET 列作为整数偏移量列表?

借助 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 列作为整数偏移量列表?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除