mysql> select * from user where name like '张%';
+----+------+-----+-----+
| id | name | age | sex |
+----+------+-----+-----+
| 2 | 张三 | 22 | 1 |
+----+------+-----+-----+
1 row in set (0.00 sec)
需求:
查询user表中姓名以七结尾的用户 语句:
mysql> select * from user where name like '%七';
+----+------+-----+-----+
| id | name | age | sex |
+----+------+-----+-----+
| 6 | 田七 | 37 | 1 |
+----+------+-----+-----+
1 row in set (0.00 sec)
需求:
查询user表中姓名中包含李字符的用户 语句:
mysql> select * from user where name like '%李%';
+----+--------+-----+-----+
| id | name | age | sex |
+----+--------+-----+-----+
| 1 | 李子捌 | 18 | 1 |
| 3 | 李四 | 38 | 1 |
+----+--------+-----+-----+
2 rows in set (0.00 sec)
mysql> select * from user where name like '李_';
+----+------+-----+-----+
| id | name | age | sex |
+----+------+-----+-----+
| 3 | 李四 | 38 | 1 |
+----+------+-----+-----+
1 row in set (0.00 sec)
需求:
查询user表中名为三的用户 语句:
mysql> select * from user where name like '_三';
+----+------+-----+-----+
| id | name | age | sex |
+----+------+-----+-----+
| 2 | 张三 | 22 | 1 |
+----+------+-----+-----+
1 row in set (0.00 sec)
需求:
查询user表中姓名为三个子,并且第二个子为麻的用户 语句:
mysql> select * from user where name like '_麻_';
+----+--------+-----+-----+
| id | name | age | sex |
+----+--------+-----+-----+
| 5 | 六麻子 | 13 | 0 |
+----+--------+-----+-----+
1 row in set (0.00 sec)