在SELECT中使用MySQL附加通配符?
对于附加,请使用的概念concat()。语法如下-
select *from yourTableName where yourColumnName like concat('%',yourValue,'%');让我们创建一个表-
mysql> create table demo48 -> ( −> id int not null auto_increment primary key, −> name varchar(20) −> );
借助insert命令将一些记录插入表中-
mysql> insert into demo48(name) values('John Smith');
mysql> insert into demo48(name) values('John Doe');
mysql> insert into demo48(name) values('Adam Smith');
mysql> insert into demo48(name) values('David Miller');
mysql> insert into demo48(name) values('Chris Brown');使用select语句显示表中的记录-
mysql> select *from demo48;
这将产生以下输出-
+----+--------------+ | id | name | +----+--------------+ | 1 | John Smith | | 2 | John Doe | | 3 | Adam Smith | | 4 | David Miller | | 5 | Chris Brown | +----+--------------+ 5 rows in set (0.00 sec)
以下是在选择语句中附加通配符的查询-
mysql> select *from demo48 where name like concat('%','Smith','%');这将产生以下输出-
+----+------------+ | id | name | +----+------------+ | 1 | John Smith | | 3 | Adam Smith | +----+------------+ 2 rows in set (0.00 sec)
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西