将此查询限制为仅显示 2 位小数

Limit this query to only show to 2 decimal places

我需要将查询更改为 return 只有 2 个小数点

SELECT (AVG(cost)) AS 'Average Cost $'
FROM donuts
WHERE cost;

我不想使用 ROUND 函数,因为我得不到小数。

SELECT ROUND(AVG(cost)) AS 'Average Cost $'
FROM donuts
WHERE cost;

任何建议,

您将使用 mysql round() 函数获得小数点。您必须传递要显示的小数点数。默认值为 0。

例如,为了得到 2 个小数点,您将 运行 这个查询:

SELECT ROUND(AVG(cost), 2) AS 'Average Cost $'
FROM donuts
WHERE cost > 0;

http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_round