MySQL Forums
Forum List  »  MySQL Query Browser

Problem Query
Posted by: barry woolgar
Date: March 28, 2012 11:01AM

Hi

I am having a problem trying to add a ranking to a query, please see below what i am trying to achieve;

Name Score Rank
A 6 1
B 4 2
c 4 2
D 4 2
E 1 5

But here is what i get;

Name Score Rank
A 6 1
B 4 2
c 4 2
D 4 2
E 1 3

Row 'E' is not staying in the correct flow for the rank.

Here is the query i am using;

SET @rank = 0, @prev_val = NULL;
SELECT * FROM
(SELECT Name, @rank := IF(@prev_val=score,@rank,@rank+1) AS rank,
@prev_val := score AS score
FROM temp_scorecount2
group by site ORDER BY score DESC)as result;

Please help!

Options: ReplyQuote


Subject
Written By
Posted
Problem Query
March 28, 2012 11:01AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.