Joining tables based on the maximum value

后端 未结 6 1715
暖寄归人
暖寄归人 2021-02-08 22:00

Here\'s a simplified example of what I\'m talking about:

Table: students      exam_results
_____________       ____________________________________
| id | name |         


        
6条回答
  •  醉酒成梦
    2021-02-08 22:45

    SELECT s.name,
        COALESCE(MAX(er.score), 0) AS high_score
    FROM STUDENTS s
        LEFT JOIN EXAM_RESULTS er ON er.student_id = s.id
    GROUP BY s.name
    

提交回复
热议问题