Reputation: 47
If i have a series of 10 objects with rating from 1 to 10. Then how can i calculate overall rating?
For example if i have a list like this:
Entertainment - 8/10
Fun - 9/10
Comedy - 6/10
Dance - 8/10
and so on... Like this 10 objects. Tell me how to calculate the overall rating for 10.
Overall - ?/10
I am very weak in maths. I was told by someone to add the total and if I got 83 as the answer, then the overall rating will be 8.3/10. Is this correct?
I am doing this for my PHP website. So if someone knows how to write a query for this, that would be very helpful for me.
Upvotes: 1
Views: 1307
Reputation:
Yes, to get the average, add them all together and divide by the amount. Example:
//do a MySQL query instead of this
$result_out_of_10 = array(
'fun' => 9,
'comedy' => 6,
'dance' => 8
);
$total = 0;
$total_results = 0;
foreach( $result_out_of_10 as $result )
{
$total += $result;
$total_results++;
}
$final_average_out_of_10 = $total / $total_results;
print "Average rating: $final_average_out_of_10 out of 10.";
EDIT: Meherzad has a better way - using the MySQL AVG()
function - which I didn't know about. Use his way instead (although mine still works, it's more code than necessary).
Upvotes: 1
Reputation: 8553
Average the total rating and you will get the answer.
he one that is told for will stand correct if there are 10 criteria on which scoring is to be made.
SELECT avg(score) FROM tbl
There is inbuilt function available for it Refer http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_avg
Upvotes: 1