模糊查询——like
# 模糊查询——like
where .. like
%
符号代表多个字符_
符号代表一个字符
# Example
+----+------+
| id | name |
+----+------+
| 1 | Tom |
| 2 | Jim |
| 3 | Anna |
| 4 | 张三 |
| 5 | 李四 |
+----+------+
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# %
百分号
select name from student where name like 'A%';
1
+------+
| name |
+------+
| Anna |
+------+
1
2
3
4
5
2
3
4
5
show variables like 'character_set_%';
1
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.7\share\charsets\ |
+--------------------------+---------------------------------------------------------+
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# _
下划线
select name from student where name like '张_';
1
+------+
| name |
+------+
| 张三 |
+------+
1
2
3
4
5
2
3
4
5
select name from student where name like 'An__';
1
+------+
| name |
+------+
| Anna |
+------+
1
2
3
4
5
2
3
4
5
编辑 (opens new window)
上次更新: 2022/09/26, 16:55:15