Can anybody help as what is wrong in this query ?


  • 0
    D

    SELECT @score := s.score, @rank:= IF (@prev_score != s.score, @rank:=@rank + 1 and @prev_score := @score, @rank := @rank) rank FROM Scores s, (SELECT @score := 0, @rank := 0, @prev_score := NULL) r ORDER BY score DESC


  • 0

    Could you please at least elaborate on what result you got for that query, and your expected result?


  • 0
    B
    This post is deleted!

  • 0
    D

    SELECT @current_score:=s.Score, @prev_score,IF (@prev_score <> @current_score, ((@prev_score := @current_score) and @rank := @rank + 1) , @rank := @rank) Rank
    FROM Scores s, (SELECT @current_score :=0, @rank := 0, @prev_score := 0) r
    ORDER BY s.Score DESC .. " I just rewrote the query but later I figured out that, "If" won;t work because of the casting issues of double to int during assignment in my IF condition. The Query I rewrote is proper but can anybody solve the typecast issue then this would work.


  • 0
    D

    The output of the above query can be seen in SQL fiddle:
    http://www.sqlfiddle.com/#!2/dc9b4d/243


  • 0
    D

    Hi brayden, thanks for the reply, but can you help me solve the casting issue of the below query : SELECT @current_score:=s.Score, @prev_score,IF (@prev_score <> @current_score, ((@prev_score := @current_score) and @rank := @rank + 1) , @rank := @rank) Rank
    FROM Scores s, (SELECT @current_score :=0, @rank := 0, @prev_score := 0) r
    ORDER BY s.Score DESC

    The output of the above query can be seen in SQL fiddle:
    http://www.sqlfiddle.com/#!2/dc9b4d/243


  • 0
    K

    Why do you think you need a variable here?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.