将MySQL数据库值一起添加

I am doing a high scores page for user to accumulate their score. Under the database table there are username, score and difflevel (the difficulty level). Username would be what they use to login and attempt the quiz, score would be how much marks they received from the questions.

My question is how do you add up the database values, for example, "Tom scored 5 points from the quiz today, and he scored 3 points the next day, I want the accumulated sum of 5+3=8. However in the database is his entry of 5 and 3 only.

Currently, I can only display the top scorers but the high score is not cumulative.

Is it possible to add them up(making them cumulative) and display it on the web page? I need this information because I want to show the top 5 scorers of the month or year.

SQL (and specifically, MySQL, in your case) has a set of functions called aggregate functions which take several values from a column(s) and produce a single result. In your case, you'd use the sum function. You can use these functions with a group by clause to separate the result per distinct value of another column. So, in your case:

SELECT   username, SUM(score)
FROM     my_table
GROUP BY username
ORDER BY 2 DESC