模糊查询
通配符
- 通配符
_ [下划线]
表示任意一个字符
%
表示任意字符
# 满足“T_m”的有(A、C)
A:Tom B:Toom C:Tam D:Tm E:Tmo
# 满足“T_m_”的有( B C)
A:Tmom B:Tmmm C:T1m2 D:Tmm E:Tm
# 满足“张%”的是(ABCD)
A:张三 B:张三丰 C:张牙舞爪 D:张 E:小张
# 满足“%诺基亚%”的是(ABCD)
A:诺基亚2100 B:2100诺基亚 C:把我的诺基亚拿过来 D:诺基亚
模糊查询(like)
mysql> select * from stu where stuname like 'T_m';
+--------+---------+--------+--------+---------+------------+------+------+
| stuNo | stuName | stuSex | stuAge | stuSeat | stuAddress | ch | math |
+--------+---------+--------+--------+---------+------------+------+------+
| s25320 | Tom | 男 | 24 | 8 | 北京 | 65 | 67 |
+--------+---------+--------+--------+---------+------------+------+------+
# `1 row in set (0.00 sec)`
-- 查询姓张的学生
mysql> select * from stu where stuname like '张%';
+--------+---------+--------+--------+---------+------------+------+------+
| stuNo | stuName | stuSex | stuAge | stuSeat | stuAddress | ch | math |
+--------+---------+--------+--------+---------+------------+------+------+
| s25301 | 张秋丽 | 男 | 18 | 1 | 北京 | 80 | NULL |
+--------+---------+--------+--------+---------+------------+------+------+
# `1 row in set (0.00 sec)`