Reputation: 352
I want to rating my property to restrict the user to rate it only once. So i am saving rating points and user id in the table.
Now i want the total avg rating of that property.
I am using my query like this
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
But i am getting errors. How can i get that total average rating. Thanks
Upvotes: 1
Views: 3163
Reputation: 38584
Use this
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
Upvotes: 2