在某些帶下劃線的列值中使用 MySQL IN()


我們首先建立一個表 −

mysql> create table DemoTable1363
    -> (
    -> StudentId varchar(20)
    -> );
Query OK, 0 rows affected (0.57 sec)

使用 insert 命令在表中插入一些記錄 −

mysql> insert into DemoTable1363 values('901');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable1363 values('702');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable1363 values('901_John_Doe');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1363 values('1001_Carol_Taylor');
Query OK, 1 row affected (0.26 sec)

使用 select 語句顯示錶中的所有記錄 −

mysql> select * from DemoTable1363;

這將產生以下輸出 −

+-------------------+
| StudentId         |
+-------------------+
| 901               |
| 702               |
| 901_John_Doe      |
| 1001_Carol_Taylor |
+-------------------+
4 rows in set (0.00 sec)

以下是實現 IN() 的 MySQL 查詢 −

mysql> select * from DemoTable1363 where StudentId IN('702','1001');

這將產生以下輸出 −

+-----------+
| StudentId |
+-----------+
| 702       |
+-----------+
1 row in set (0.00 sec)

更新時間: 08-11-2019

138 次瀏覽

開啟你的 職業生涯

完成課程獲取認證

開始學習
廣告