如何使 MySQL 中的数字“人可读”?


要把数字“变成人可读”格式(即包含分隔符),你需要使用 format()。让我们先创建一个表 -

mysql> create table DemoTable859(Number bigint);
Query OK, 0 rows affected (1.54 sec)

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

mysql> insert into DemoTable859 values(747464646473737);
Query OK, 1 row affected (0.45 sec)
mysql> insert into DemoTable859 values(3836365366464);
Query OK, 1 row affected (0.71 sec)
mysql> insert into DemoTable859 values(8376437647433);
Query OK, 1 row affected (0.46 sec)

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

mysql> select *from DemoTable859;

将产生以下输出 -

+-----------------+
| Number          |
+-----------------+
| 747464646473737 |
| 3836365366464   |
| 8376437647433   |
+-----------------+
3 rows in set (0.00 sec)

以下是使 MySQL 中的数字“变成人可读”格式的查询 -

mysql> select format(Number, 0) AS HumanReadableFormat from DemoTable859;

将产生以下输出 -

+---------------------+
| HumanReadableFormat |
+---------------------+
| 747,464,646,473,737 |
| 3,836,365,366,464   |
| 8,376,437,647,433   |
+---------------------+
3 rows in set (0.00 sec)

更新时间: 03-9 月 -2019

365 次浏览

开启您的职业生涯

完成课程后获得认证

开始
广告
© . All rights reserved.