Left join


  • 0
    C
    
    SELECT
    d.dept_name
    ,CASE WHEN s.student_number > 0 then s.student_number else 0 end as student_number
    FROM department d
    LEFT JOIN
        (SELECT dept_id, count(student_id) as student_number FROM student GROUP BY dept_id) s
    ON s.dept_id = d.dept_id
    ORDER BY s.student_number DESC, d.dept_name
    

Log in to reply
 

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