My solution using coalesce


  • 1
    S
    SELECT department.dept_name, COALESCE(student_number, 0) AS student_number
    FROM department
    LEFT JOIN
    (SELECT count(student_id) as student_number, dept_id
        FROM student
        GROUP BY dept_id ) t1 
     ON t1.dept_id = department.dept_id
    ORDER BY t1.student_number DESC, department.dept_name ```

Log in to reply
 

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