查找在MySQL中排第二位的特定记录

为此,请使用SUBSTR()以下语法-

select * from yourTableName
where substr(yourColumnName, 2, 1 ) = ' ';

让我们首先创建一个表-

mysql> create table DemoTable1365
    -> (
    -> Value varchar(20)
    -> );

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

mysql> insert into DemoTable1365 values('9756757474');
mysql> insert into DemoTable1365 values('3 45322333');
mysql> insert into DemoTable1365 values('8974646363');
mysql> insert into DemoTable1365 values('9 566363622');

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

mysql> select * from DemoTable1365;

这将产生以下输出-

+-------------+
| Value       |
+-------------+
| 9756757474  |
| 3 45322333  |
| 8974646363  |
| 9 566363622 |
+-------------+
4 rows in set (0.00 sec)

这是查询以查找表中的特定记录,该记录仅在第二位具有空格,例如“ 3 4532”-

mysql> select * from DemoTable1365
    -> where substr(Value, 2, 1 ) = ' ';

这将产生以下输出-

+-------------+
| Value       |
+-------------+
| 3 45322333  |
| 9 566363622 |
+-------------+
2 rows in set (0.00 sec)