Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Rank the scores

    Rank the scores

    Mediumsqlwindow functionsdense rank

    Return score and rank for every row in results. The highest gets rank 1, equal scores share a rank, and there are no gaps (two 1s are followed by 2). Sort from highest, then by id.

    Tables

    • results (id INTEGER, score INTEGER)

    Example 1

    results

    idscore
    1350
    2365
    3400
    4385
    5400
    6365

    Expected result

    scorerank
    4001
    4001
    3852
    3653
    3653
    3504

    Constraints

    • 0 ≤ rows ≤ 1000
    • The order of rows matters

    Submit checks your solution against 7 tests, including hidden ones.

    SQL
    -- Write one SELECT query. Tables: results
    SELECT
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.