|
-
Senior Member
The syntax is basically,
SELECT usernameSQL, scoreSQL
FROM scores
[ORDER BY scoreSQL [DESC , ASC]]
[LIMIT 10];
Brackets meaning those lines are optional. Default ordering is ascending. Limiting takes place after ordering, so you'll either get the top ten or bottom ten scores this way.
For most applications, we would not use a string username field for this table. We'd make it an unsigned integer which matched a userID in a separate table for users, and join that table with the syntax:
SELECT users.username, scores.score
FROM scores
INNER JOIN users ON users.userID=scores.userID
ORDER BY scores.score DESC
LIMIT 10;
That way you could also get the average score per player like this:
SELECT AVG(scores.score) AS avgscore, users.username
FROM users
LEFT OUTER JOIN scores ON scores.userID=users.userID
GROUP BY users.userID
ORDER BY avgscore DESC
LIMIT 10;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|