0

我正在运行 MySQL 5.5.3 版。我有这个代码:

SELECT DISTINCT model, round(avg(overallRating),1)
FROM car_ratings, car_details
WHERE car_ratings.carId = car_details.carId
AND make = 'HOLDEN'
GROUP BY model
ORDER BY avg(overallRating) DESC, model ASC

这给了我“霍顿”制造车辆中每种型号的平均评分。它工作正常,除了它将数字 4.050 向上舍入到 4.1。有没有办法让这个数字四舍五入?所以它给了我 4.0 而不是 4.1。

4

1 回答 1

1

您是否希望在所有情况下都四舍五入?如果是这样,您正在寻找 FLOOR

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

SELECT DISTINCT model, FLOOR(avg(overallRating) * 10) / 10 -- HERE
FROM car_ratings, car_details
WHERE car_ratings.carId = car_details.carId
AND make = 'HOLDEN'
GROUP BY model
ORDER BY avg(overallRating) DESC, model ASC
于 2013-05-20T01:46:46.960 回答