为此,请使用REGEXP并获取以特定编号开头的记录。以下是语法:Select yourColumnName1,yourColumnName2
from yourTableName
where yourColumnName2 REGEXP '^yourStringValue[yourNumericValue]';
让我们创建一个表-mysql> create table demo45
-> (
−> id int not null auto_increment primary key,
−> value varchar(50)
−> );
借助insert命令将一些记录插入表中。我们将插入包含字符串和数字(例如“ John500,“ John6500””等)的记录-mysql> insert into demo45(value) values('John500');
mysql> insert into demo45(value) values('John1500');
mysql> insert into demo45(value) values('John5500');
mysql> insert into demo45(value) values('John6500');
mysql> insert into demo45(value) values('John8600');
使用select语句显示表中的记录-mysql> select *from demo45;
这将产生以下输出-+----+----------+
| id | value |
+----+----------+
| 1 | John500 |
| 2 | John1500 |
| 3 | John5500 |
| 4 | John6500 |
| 5 | John8600 |
+----+----------+
5 rows in set (0.00 sec)
以下是查询以获取具有特定编号的记录,即此处的5和6-mysql> select id,value
−> from demo45
−> where value REGEXP '^John[56]';
这将产生以下输出-+----+----------+
| id | value |
+----+----------+
| 1 | John500 |
| 3 | John5500 |
| 4 | John6500 |
+----+----------+
3 rows in set (0.00 sec)