是department left join student。我们要找出dep的信息,无论有没有对应的stu。
COUNT()中要是stu的信息,这样才是stu的数量。
SELECT d.dept_name, COUNT(s.student_id) AS student_numberFROM department d LEFT JOIN student sON d.dept_id=s.dept_idGROUP BY d.dept_idORDER BY student_number DESC, d.dept_name;