MySQL中货币的最佳数据类型是什么? | 您所在的位置:网站首页 › sql中的decimal › MySQL中货币的最佳数据类型是什么? |
MySQL中货币的最佳数据类型是DECIMAL。DECIMAL数据类型的语法如下- DECIMAL(TotalDigit,NumberOfDigitAfterDecimalPoint);为了理解上述语法,让我们创建一个表。创建表的查询如下- mysql> create table CurrenciesDemo -> ( -> TotalPrice DECIMAL(10,2) -> );使用insert命令在表中插入一些记录。查询如下- mysql> insert into CurrenciesDemo values(1647575.67); mysql> insert into CurrenciesDemo values(1647575); mysql> insert into CurrenciesDemo values(99599596); mysql> insert into CurrenciesDemo values(1986.50); mysql> insert into CurrenciesDemo values(99999999.90);使用select语句显示表中的所有记录。查询如下- mysql> select *from CurrenciesDemo;以下是输出- +-------------+ | TotalPrice | +-------------+ | 1647575.67 | | 1647575.00 | | 99599596.00 | | 1986.50 | | 99999999.90 | +-------------+ 5 rows in set (0.00 sec)以下是查询以显示所有上述价格,并带有前缀符号,例如dollar- mysql> select concat('$',TotalPrice) as DollerSign from CurrenciesDemo;以下是输出- +--------------+ | DollerSign | +--------------+ | $1647575.67 | | $1647575.00 | | $99599596.00 | | $1986.50 | | $99999999.90 | +--------------+ 5 rows in set (0.00 sec) |
CopyRight 2018-2019 实验室设备网 版权所有 |