mysql与格式相加

时间:2015-10-06 05:50:08

标签: mysql sum format

我想对我的属性进行评级,以限制用户仅对其进行一次评分。 所以我在表中保存了评分和用户ID。

现在我想要该房产的总平均评级。

我正在使用我的查询

SELECT SUM(rating_number) as rating_number, FORMAT((SUM(total_points) / SUM(rating_number),1) as average_rating FROM post_rating WHERE post_id = 9781 AND status = 1

但我收到错误。我怎样才能获得总平均评分。 感谢

1 个答案:

答案 0 :(得分:2)

使用此

SELECT SUM(rating_number) as rating_number, 
FORMAT((SUM(total_points) / SUM(rating_number)),2) as average_rating
FROM post_rating WHERE post_id = 9781 AND status = 1