Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Departments with Window Functions

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Rank Departments with Window Functions. Start with the requirements and the three tables on the right.

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.

Problem

The University of Chicago's research administration team wants to compare external research funding growth across academic departments. Write a PostgreSQL query that ranks eligible departments by the percentage change in awarded external grant funding from fiscal year 2023 to fiscal year 2024.

Requirements

  1. Include only grants with status = 'Awarded' and funders marked as external.
  2. Aggregate grant amounts by department and fiscal year, treating missing 2024 funding as zero.
  3. Calculate absolute and percentage growth from 2023 to 2024.
  4. Exclude departments with no positive 2023 baseline, and rank the remaining departments by percentage growth descending using a window function.
  5. Return department name, both annual totals, growth amounts, growth percentage, and rank.

Schema

departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(120)University of Chicago department name
funders
ColumnTypeDescription
funder_idPKINTUnique funder identifier
funder_nameVARCHAR(120)Funding organization name
is_externalBOOLEANWhether the funder is external to UChicago
research_grants
ColumnTypeDescription
grant_idPKINTUnique grant identifier
department_idINTDepartment receiving the grant
funder_idINTFunder issuing the grant
fiscal_yearINTFiscal year associated with the grant
award_amountNUMERIC(14,2)Grant award amount in US dollars
statusVARCHAR(30)Grant lifecycle status
grant_titleVARCHAR(180)Short grant title
Tablesdepartmentsresearch_grantsfunders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results