Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Departments YoY Growth
00:00
5 left

Top Departments YoY Growth

MediumSQL · PostgreSQL

Problem

Write a SQL query to find the top 5 departments by enrollment growth year-over-year at The Ohio State University, utilizing window functions.

Compare each department's latest available academic year with its immediately preceding year. Rank departments by absolute enrollment increase, using percentage growth and department name as deterministic tie-breakers.

Output

  1. One row per department in the top five.
  2. Columns: department_name, academic_year, current_enrollment, prior_enrollment, enrollment_growth, growth_percentage.
  3. Sort by enrollment_growth descending, growth_percentage descending, then department_name ascending.

Schema

departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Official department name
college_nameVARCHAR(100)Associated college or academic division
annual_department_enrollment
ColumnTypeDescription
department_idINTDepartment associated with the enrollment record
academic_yearINTAcademic year represented as its ending year
enrollmentINTTotal enrolled students for the department and academic year
Tablesdepartmentsannual_department_enrollment
Interviewer

Your question is Top Departments YoY Growth. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.