Worked in Mysql, but does not work here


  • 0
    H

    code:
    select Score, rank from(
    select -1 as Score, -1 as rank, -1 as PreScore from Scores where (@rank := 0) >1 and (@pre := -1) >0
    union all
    select Score, @rank := if(Score = @Pre,@rank, @rank +1) as rank,
    @pre:= Score as PreScore from Scores order by Score desc
    ) TempScore order by rank;

    the failed cases:
    Input: {"headers": {"Scores": ["Id", "Score"]}, "rows": {"Scores": [[1, 0.00], [2, 0.00]]}}
    Output: {"headers": ["Score", "rank"], "values": [[0.00, 0], [0.00, 0]]}
    Expected: {"headers": ["Score", "Rank"], "values": [[0.00, 1], [0.00, 1]]}

    However the output is [0.00, 1], [0.00, 1] in MYSQL


Log in to reply
 

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