在 MySQL 中获取特定的列值(名称)


要获取特定的列值,请使用 LIKE 子句。我们先创建一个表 -

mysql> create table DemoTable1809
     (
     Name varchar(20)
     );
Query OK, 0 rows affected (0.00 sec)

使用插入命令在表中插入一些记录 -

mysql> insert into DemoTable1809 values('John');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('David');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('Mike');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('Johnson');
Query OK, 1 row affected (0.00 sec)

使用 select 语句从表中显示所有记录 -

mysql> select * from DemoTable1809;

这将产生以下输出 -

+---------+
| Name    |
+---------+
| John    |
| David   |
| Mike    |
| Johnson |
+---------+
4 rows in set (0.00 sec)

以下是获取特定值的查询

mysql> select * from DemoTable1809 where Name LIKE 'Johnson%';

这将产生以下输出 -

+---------+
| Name    |
+---------+
| Johnson |
+---------+
1 row in set (0.00 sec)

更新于: 2019-12-24

760 次浏览

开启你的 职业生涯

完成课程获取认证

开始
广告
© . All rights reserved.