Answers for "sql select students closest in score"

SQL
0

sql select students closest in score

SELECT 
    s1.student AS one_student
    , s2.student AS other_student
    , ABS(s1.score - s2.score) AS score_diff
FROM scores AS s1
INNER JOIN scores AS s2
    ON s1.id != s2.id
        AND s1.id < s2.id
ORDER BY 3 ASC, 1 ASC
LIMIT 1
Posted by: Guest on March-30-2022

Code answers related to "SQL"

Browse Popular Code Answers by Language