在 MySQL 中实施增量式搜索并显示具有特定数字的值?
为此,你可以使用 SUBSTRING_INDEX()。我们先创建一个表 -
mysql> create table DemoTable (Number varchar(100)); Query OK, 0 rows affected (0.60 sec)
示例
使用插入命令在表中插入一些记录 -
mysql> insert into DemoTable values('235678'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('1634990'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('678590'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable values('908765432'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('222343388773'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values('09028215'); Query OK, 1 row affected (0.51 sec)
使用选择语句从表中显示所有记录 -
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)
广告