MySQL select 来将数字转换为百万和十亿格式?
您可以使用 MySQL 的 FORMAT() 将数字转换为百万和十亿格式。让我们首先创建一个表 -
mysql> create table DemoTable ( Value BIGINT ); Query OK, 0 rows affected (0.74 sec)
使用 insert 命令向表中插入记录 -
mysql> insert into DemoTable values(78000000000); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10000000000); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(90000000000); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(450600000000); Query OK, 1 row affected (0.41 sec)
使用 select 语句显示表中的所有记录 -
mysql> select *from DemoTable;
这将产生以下输出 -
+--------------+ | Value | +--------------+ | 78000000000 | | 10000000000 | | 90000000000 | | 450600000000 | +--------------+ 4 rows in set (0.00 sec)
以下是将数字转换为百万和十亿格式的查询 -
mysql> select format(Value,0) as `FormatValue` from DemoTable;
这将产生以下输出 -
+-----------------+ | FormatValue | +-----------------+ | 78,000,000,000 | | 10,000,000,000 | | 90,000,000,000 | | 450,600,000,000 | +-----------------+ 4 rows in set (0.00 sec)
广告