选择以某些数字开头的记录的最佳解决方案是使用MySQL LIKE运算符。让我们首先创建一个表-
mysql> create table DemoTable ( ClientId bigint, ClientName varchar(40) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(23568777,'Chris Brown'); mysql> insert into DemoTable values(9085544,'John Doe'); mysql> insert into DemoTable values(9178432,'John Doe'); mysql> insert into DemoTable values(9078482,'David Miller');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+--------------+ | ClientId | ClientName | +----------+--------------+ | 23568777 | Chris Brown | | 9085544 | John Doe | | 9178432 | John Doe | | 9078482 | David Miller | +----------+--------------+ 4 rows in set (0.00 sec)
以下是查询以选择在MySQL中以某些数字开头的记录的查询-
mysql> select *from DemoTable where ClientId LIKE '90%';
这将产生以下输出-
+----------+--------------+ | ClientId | ClientName | +----------+--------------+ | 9085544 | John Doe | | 9078482 | David Miller | +----------+--------------+ 2 rows in set (0.00 sec)