立即学习:https://edu.csdn.net/course/play/27328/362526?utm_source=blogtoedu
IN 和 LIKE 的使用
# 查询 id 在(1, 2, 3)这三个数中的任一个的员工信息
select * from employee where id in(1,2,3);
+----+--------+------+--------+
| id | name | sex | salary |
+----+--------+------+--------+
| 1 | 张三 | 男 | 5500 |
| 2 | 李洁 | 女 | 4500 |
| 3 | 李小梅 | 女 | 4200 |
+----+--------+------+--------+
3 rows in set (0.03 sec)
# 查询名字以 ’李‘ 开头的员工信息
mysql> select * from employee where name like '李%';
+----+--------+------+--------+
| id | name | sex | salary |
+----+--------+------+--------+
| 2 | 李洁 | 女 | 4500 |
| 3 | 李小梅 | 女 | 4200 |
| 5 | 李芳 | 女 | 8500 |
| 7 | 李四 | 男 | 12000 |
+----+--------+------+--------+
4 rows in set (0.03 sec)
# 查询名字以 ’李‘ 开头,且名字为两个字的员工的信息
mysql> select * from employee where name like '李_';
+----+------+------+--------+
| id | name | sex | salary |
+----+------+------+--------+
| 2 | 李洁 | 女 | 4500 |
| 5 | 李芳 | 女 | 8500 |
| 7 | 李四 | 男 | 12000 |
+----+------+------+--------+
3 rows in set (0.00 sec)
# 查询名字中带 ’小‘ 字的员工信息
mysql> select * from employee where name like '%小%';
+----+--------+------+--------+
| id | name | sex | salary |
+----+--------+------+--------+
| 3 | 李小梅 | 女 | 4200 |
| 9 | 马小龙 | 男 | 6000 |
| 11 | 冯小芳 | 女 | 10000 |
| 12 | 马小花 | 女 | 4000 |
+----+--------+------+--------+
4 rows in set (0.00 sec)