我們如何取得 MySQL SET 列作為整數偏移量清單?

王林
發布: 2023-08-25 19:21:03
轉載
1402 人瀏覽過

我们如何获取 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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!