Reputation: 147
I am saving the scores of a game with PHP and MySQL, the table looks like this.
ID USERID SCORE
1 23 200
2 45 145
3 64 231
etc...
Now what PHP or MySQL code can let me show the average scores ? Thanks.
Upvotes: 0
Views: 659
Reputation: 2113
For entire table
SELECT AVG(score) AS average_score FROM 'table'
Upvotes: 0
Reputation: 120704
A user's average score? This should do it:
SELECT USERID, AVG(SCORE) AS AVERAGE_SCORE
FROM
TABLE_NAME
GROUP BY
USERID
For the entire table:
SELECT AVG(SCORE) AS AVERAGE_SCORE
FROM
TABLE_NAME
Upvotes: 1