MySQL查询在某一列中查找特定姓的基本搜索
你可以使用LIKE操作符来对姓氏进行基本搜索。让我们首先创建一个表: -
mysql> create table DemoTable -> ( -> CustomerName varchar(100), -> CustomerAge int -> ); Query OK, 0 rows affected (0.77 sec)
使用insert命令将一些记录插入表中 -
mysql> insert into DemoTable values('John Doe',34); Query OK, 1 row affected (1.32 sec) mysql> insert into DemoTable values('David Miller',24); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob Doe',27); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Carol Taylor',29); Query OK, 1 row affected (0.13 sec)
使用select语句显示表中的所有记录 -
mysql> select *from DemoTable;
输出
将产生以下输出 -
+--------------+-------------+ | CustomerName | CustomerAge | +--------------+-------------+ | John Doe | 34 | | David Miller | 24 | | Bob Doe | 27 | | Carol Taylor | 29 | +--------------+-------------+ 4 rows in set (0.00 sec)
以下是查询某一列中姓氏的方法 -
mysql> select *from DemoTable where CustomerName LIKE '%Doe%';
输出
将产生以下输出 -
+--------------+-------------+ | CustomerName | CustomerAge | +--------------+-------------+ | John Doe | 34 | | Bob Doe | 27 | +--------------+-------------+ 2 rows in set (0.00 sec)
广告