Home > Database > Mysql Tutorial > How can we get MySQL SET column as a list of integer offsets?

How can we get MySQL SET column as a list of integer offsets?

王林
Release: 2023-08-25 19:21:03
forward
1431 people have browsed it

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

With the help of the MAKE_SET() function, we can get the MySQL SET column value in the form of a list of integer offsets. For ease of understanding, we create a table named "set_testing" as shown below -

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)
Copy after login

Now, the following query will get the MySQL SET column as a list of integer offsets -

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)
Copy after login

The above is the detailed content of How can we get MySQL SET column as a list of integer offsets?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template