【发布时间】:2014-01-26 08:12:00
【问题描述】:
我不太了解这里的cast 函数和decimal。 decimal(7,2) 究竟是什么意思? The first part and the second part arg of the function.
这里为什么需要cast/convert我的浮点数转十进制?
mysql> SELECT productCode, MAX(price), MIN(price),
CAST(AVG(price) AS DECIMAL(7,2)) AS `Average`,
CAST(STD(price) AS DECIMAL(7,2)) AS `Std Dev`,
SUM(quantity)
FROM products
GROUP BY productCode;
+-------------+------------+------------+---------+---------+---------------+
| productCode | MAX(price) | MIN(price) | Average | Std Dev | SUM(quantity) |
+-------------+------------+------------+---------+---------+---------------+
| PEC | 0.49 | 0.48 | 0.49 | 0.01 | 18000 |
| PEN | 1.25 | 1.23 | 1.24 | 0.01 | 15000 |
+-------------+------------+------------+---------+---------+---------------+
下面是一个相同的 sql fiddle?。
http://sqlfiddle.com/#!2/1ed51b/1/0
我的问题再次重复:
-
decimal(7,2)究竟是什么意思?The first part and the second part arg of the function. - 这里为什么需要
cast/convert我的浮点数转十进制?。
【问题讨论】: