I am not quite understanding the cast
function and decimal
here. What does decimal(7,2)
actually mean?. The first part and the second part arg of the function.
Why do i need to cast/convert
my floating point to decimal here?.
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 |
+-------------+------------+------------+---------+---------+---------------+
Below is a sql fiddle for the same?.
http://sqlfiddle.com/#!2/1ed51b/1/0
My Questions again repeated:
- What does
decimal(7,2)
actually mean?.The first part and the second part arg of the function.
- Why do i need to
cast/convert
my floating point to decimal here?.