要拆分数字查询结果,可以CONCAT()在MySQL中使用该函数。让我们首先创建一个表-mysql> create table DemoTable
(
StudentId int
);
现在您可以使用insert命令在表中插入一些记录-mysql> insert into DemoTable values(2222);
mysql> insert into DemoTable values(5555);
mysql> insert into DemoTable values(4567);
mysql> insert into DemoTable values(8905);
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
输出结果+-----------+
| StudentId |
+-----------+
| 2222 |
| 5555 |
| 4567 |
| 8905 |
+-----------+
4 rows in set (0.00 sec)
以下是拆分数值查询结果的查询。在这里,我们分割了值的第一位-mysql> select concat(left(StudentId, 1), '/',right(StudentId, length(StudentId)-1)) splitNumericalValue from DemoTable;
输出结果+---------------------+
| splitNumericalValue |
+---------------------+
| 2/222 |
| 5/555 |
| 4/567 |
| 8/905 |
+---------------------+
4 rows in set (0.00 sec)