Mickey Slater
Mickey Slater

Reputation: 404

How do i get mysql rank to go in the proper diretion

Helllo.

I am writing a query to do a couple things. Users are assigned a team, each user has points, I am grouping users by their team name and tallying their points. I also assign a rank.

It all works fine but the Ranking give a rank of 1 to the lowest score instead of the highest score. This is my query

SELECT users.teamname as Team, users.points AS Score, COUNT(users.points) AS Members, @curRank := @curRank + 1 AS Rank
FROM users,(SELECT @curRank := 0) r
WHERE !(teamname is null)
GROUP BY `teamname`
ORDER BY Score

I think i have to nest something but I have never done something like that before.

Upvotes: 0

Views: 52

Answers (1)

Dan Bracuk
Dan Bracuk

Reputation: 20804

The problem might be:

ORDER BY Score

since you didn't specify a direction, it's ascending. In other words, the lowest value is at the top. To put the highest value at the top do this:

ORDER BY Score desc

or it might be something else.

Upvotes: 2

Related Questions