chaitanya
chaitanya

Reputation: 352

mysql sum with format

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

Answers (1)

Abdulla Nilam
Abdulla Nilam

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

Related Questions