Calculate average of column from MYSQL query

DoubleA picture DoubleA · Jan 6, 2012 · Viewed 91.4k times · Source

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)?

Answer

zerkms picture zerkms · Jan 6, 2012

You can use AVG like so:

SELECT AVG(P1_Score)