要格式化记录,请使用FORMAT()。让我们首先创建一个表-mysql> create table DemoTable
-> (
-> Price decimal(10,4),
-> Rate decimal(10,4)
-> );
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values(1000,10.2);
mysql> insert into DemoTable values(2000,20.4);
mysql> insert into DemoTable values(100,5);
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
这将产生以下输出-+-----------+---------+
| Price | Rate |
+-----------+---------+
| 1000.0000 | 10.2000 |
| 2000.0000 | 20.4000 |
| 100.0000 | 5.0000 |
+-----------+---------+
3 rows in set (0.00 sec)
以下是格式化记录的查询-mysql> select format((Price * Rate),2) from DemoTable;
这将产生以下输出-+--------------------------+
| format((Price * Rate),2) |
+--------------------------+
| 10,200.00 |
| 40,800.00 |
| 500.00 |
+--------------------------+
3 rows in set (0.00 sec)