Sam K.
Sam K.

Reputation: 147

How to show the average score?

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

Answers (5)

Suleman Ahmad
Suleman Ahmad

Reputation: 2113

For entire table

SELECT AVG(score) AS average_score FROM 'table' 

Upvotes: 0

Philipp
Philipp

Reputation: 15629

Try

SELECT AVG(SCORE) FROM TableName

Upvotes: 0

tommasop
tommasop

Reputation: 18765

This should work:

SELECT AVG(SCORE) FROM SCORES

Upvotes: 0

worenga
worenga

Reputation: 5856

SELECT AVG(`SCORE`) as AVG_SCORE FROM `YOURTABLE`

Upvotes: 0

Sean Bright
Sean Bright

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

Related Questions