实现增量搜索并在MySQL中显示具有特定数字的值?

为此,您可以使用SUBSTRING_INDEX()。让我们首先创建一个表-

mysql> create table DemoTable (Number varchar(100));

示例

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

mysql> insert into DemoTable values('235678');
mysql> insert into DemoTable values('1634990');
mysql> insert into DemoTable values('678590');
mysql> insert into DemoTable values('908765432');
mysql> insert into DemoTable values('222343388773');
mysql> insert into DemoTable values('09028215');

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

mysql> select *from DemoTable;

输出结果

+--------------+
| Number       |
+--------------+
| 235678       |
| 1634990      |
| 678590       |
| 908765432    |
| 222343388773 |
| 09028215     |
+--------------+
6 rows in set (0.00 sec)

以下是在MySQL中获取具有特定数字的值的查询-

mysql> select Number from DemoTable where Number LIKE '%5%' ORDER BY LENGTH(SUBSTRING_INDEX(Number, '5', 1));

输出结果

+-----------+
| Number    |
+-----------+
| 235678    |
| 678590    |
| 908765432 |
| 09028215  |
+-----------+
4 rows in set (0.00 sec)