我正在运行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
这给了我'Holden'制造车辆中每个型号的平均等级。它工作正常,除了它将数字4.050加到4.1。有没有办法让这个数字倒圆?所以它给了我4.0而不是4.1。
答案 0 :(得分: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