如何檢查特定國家/地區程式碼是否存在於包含 MySQL 的單元格中?
對於特定值,使用 FIND_IN_SET()。我們首先建立 −
mysql> create table DemoTable1439 -> ( -> CountryId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CountryCode varchar(20) -> ); Query OK, 0 rows affected (0.49 sec)
在表中插入一些記錄,使用插入 −
mysql> insert into DemoTable1439(CountryCode) values('1022_US,7894_UK');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable1439(CountryCode) values('6567_AUS,7894_UK');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1439(CountryCode) values('6567_AUS');
Query OK, 1 row affected (0.09 sec)使用 select 從表中顯示所有記錄 −
mysql> select * from DemoTable1439;
將輸出以下結果 −
+-----------+------------------+ | CountryId | CountryCode | +-----------+------------------+ | 1 | 1022_US,7894_UK | | 2 | 6567_AUS,7894_UK | | 3 | 6567_AUS | +-----------+------------------+ 3 rows in set (0.00 sec)
以下查詢用於檢查國家/地區程式碼是否存在於單元格中 −
mysql> select * from DemoTable1439
-> where find_in_set('6567_AUS',CountryCode) > 0;將輸出以下結果 −
+-----------+------------------+ | CountryId | CountryCode | +-----------+------------------+ | 2 | 6567_AUS,7894_UK | | 3 | 6567_AUS | +-----------+------------------+ 2 rows in set (0.00 sec)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP