仅在 MySQL 中包含两个连字符时检索?
为此,请使用 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)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP