MySQL 如何选择以特定数字开头的记录
选择以特定数字开头的记录的最佳解决方案是使用MySQL LIKE操作符。让我们首先创建一张表 –
mysql> create table DemoTable
(
ClientId bigint,
ClientName varchar(40)
);
Query OK, 0 rows affected (0.82 sec)
使用insert命令向表中插入一些记录 –
mysql> insert into DemoTable values(23568777,'Chris Brown');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values(9085544,'John Doe');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values(9178432,'John Doe');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values(9078482,'David Miller');
Query OK, 1 row affected (0.17 sec)
使用select语句显示表中的所有记录 –
mysql> select *from DemoTable;
这将产生以下输出 –
+----------+--------------+
| ClientId | ClientName |
+----------+--------------+
| 23568777 | Chris Brown |
| 9085544 | John Doe |
| 9178432 | John Doe |
| 9078482 | David Miller |
+----------+--------------+
四行数据,耗时0.00秒
以下是在MySQL中选择以特定数字开头的记录的查询 –
mysql> select *from DemoTable where ClientId LIKE '90%';
这将产生以下输出 –
+----------+--------------+
| ClientId | ClientName |
+----------+--------------+
| 9085544 | John Doe |
| 9078482 | David Miller |
+----------+--------------+
二行数据,耗时0.00秒
阅读更多:MySQL 教程