仅当包含两个连字符时才从 MySQL 中检索?
mysqlmysqli database
为此,请使用 LIKE 运算符。让我们首先创建一个表:
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Password varchar(100) ); Query OK, 0 rows affected (1.27 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable(Password) values('John@--123'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Password) values('---Carol234'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Password) values('--David987'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Password) values('Mike----53443'); Query OK, 1 row affected (0.30 sec)
使用 select 语句显示表中的所有记录:
mysql> select *from DemoTable;
输出
+----+---------------+ | Id | Password | +----+---------------+ | 1 | John@--123 | | 2 | ---Carol234 | | 3 | --David987 | | 4 | Mike----53443 | +----+---------------+ 4 rows in set (0.00 sec)
以下是从 MySQL 中检索是否仅包含两个连字符的查询 -
mysql> select *from DemoTable where Password like '%--%' and password not like '%---%';
输出
+----+------------+ | Id | Password | +----+------------+ | 1 | John@--123 | | 3 | --David987 | +----+------------+ 2 rows in set (0.06 sec)