I've got a table that I am trying to calculate the average of the values in a column. Here is my lookup:
SELECT SUM(P1_Score) AS value_sum FROM tblMatches Where P1_ID LIKE $playerID
Any idea how I can determine the average (sum of values / total rows)?
MySQL AVG() Function The AVG() function returns the average value of an expression.
The avg() function has the following syntax: SELECT AVG( column_name ) FROM table_name; The avg() function can be used with the SELECT query for retrieving data from a table.
The AVG() function returns the average value of an expression. Note: NULL values are ignored.
You can use AVG like so:
SELECT AVG(P1_Score)
So in your case:
$gameswon = mysql_query("SELECT AVG(P1_Score) AS value_sum FROM tblMatches WHERE P1_ID LIKE '".$playerid."'");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With