在 MySQL 中使用 LIKE 获取以特定字符开头的姓名
要获取以特定字符开头的姓名,你需要使用 LIKE。我们首先创建一个表格
mysql> create table DemoTable ( StudentFirstName varchar(20) ); Query OK, 0 rows affected (1.01 sec)
以下是使用 insert 命令在表格中插入一些记录的查询
mysql> insert into DemoTable values('John');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values('Carol');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('Johnny');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values('Robert');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable values('Chris');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values('Ramit');
Query OK, 1 row affected (0.18 sec)以下是使用 select 命令从表格中显示记录的查询
mysql> select *from DemoTable;
这将产生以下输出
+------------------+ | StudentFirstName | +------------------+ | John | | Carol | | Johnny | | Robert | | Chris | | Ramit | +------------------+ 6 rows in set (0.00 sec)
以下是使用 LIKE 匹配第一个字符的查询:即从字符 C 开始的所有学生姓名
mysql> select *from DemoTable where StudentFirstName LIKE 'C%';
这将产生以下输出
+------------------+ | StudentFirstName | +------------------+ | Carol | | Chris | +------------------+ 2 rows in set (0.00 sec)
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP