๐ Count Student Number in Departments
You're working as a database administrator for a university that needs to generate a comprehensive department report. The university maintains two tables: one tracking students and their department assignments, and another containing all department information.
Your task is to create a report showing every department along with the number of students currently enrolled in each one. This includes departments that might have zero students - the administration wants a complete picture of all departments, regardless of enrollment status.
Key Requirements:
- Show all departments from the Department table
- Count students in each department (including 0 for empty departments)
- Sort by student count (highest first), then by department name alphabetically for ties
The result should help administrators identify popular programs and departments that might need more marketing or resources.
Input & Output
Visualization
Time & Space Complexity
Single pass through departments (n) and students (m) with efficient JOIN operation
No additional space needed beyond result set and join processing
Constraints
- 1 โค Department table rows โค 100
- 0 โค Student table rows โค 1000
- All department IDs in Student table exist in Department table
- Must include departments with 0 students
- Department names are unique and non-null