• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Rank Teams | TDM
#1
Espa?ol: ?Alguien sabe como hacer un rankings de teams?, me explico, una funcion para juntar los scores de los jugadores del team, uso MySQL



English:?Does anyone know how to make a team ranking? Let me explain, a function to gather the scores of the team players, I use MySQL
Programador b?sico

  Reply
#2
SELECT and ORDER BY.

A basic query could be built as:
Code:
SELECT someData FROM someTable ORDER BY someColum;
You can order ascending or descending using ASC or DESC: "(...) ORDER BY someColumn ASC" or "(...) ORDER BY someColumn DESC"
You can limit the results using "LIMIT" (in any select query):
Code:
SELECT * FROM someTable LIMIT 5; -- Would show no more than 5 results, even if there are more results

For your situation, I'm assuming your table looks like this:
Code:
-- table "teams" --
[id] [name] [score]
1    groves    50
2    ballaz    24
3    metalheadz    85
4    poo    0
5    a-team    12
6    fez    104
7    zepheads 73

So if you'd want to show a top 3 (top ranking) based on their score, showing the highest score first you'd have to order by (ascending) column score in this case:
Code:
SELECT name, score FROM teams ORDER BY score ASC LIMIT 3;
Output for this query then would be:
Code:
[name] [score]
fez    104
metalheadz 85
zepheads 73

Note that queries may be more (way more) complex than this. However there's alot of documentation for that online. If you have any questions, use a search engine first now that you know the basics of that what you're looking for, enough information is already on the internet.
  Reply


Forum Jump: