Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Applicants With Window Functions

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

Your question is Rank Applicants 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

Stanford University’s research administration team wants to compare grant applications within each academic department. Write a PostgreSQL query that calculates each application’s average review score and ranks applications within its department.

Requirements

  1. Join applications to departments and review records.
  2. Calculate the average non-NULL review score for every application, including applications without reviews.
  3. Use RANK() partitioned by department, ordering higher average scores first. Applications without scores should appear after scored applications.
  4. Return the results ordered by department, rank, and application ID.

Schema

departments
ColumnTypeDescription
department_idPKINTEGERPrimary key for the department
department_nameVARCHAR(100)Stanford academic department name
grant_applications
ColumnTypeDescription
application_idPKINTEGERPrimary key for the grant application
applicant_nameVARCHAR(120)Applicant or principal investigator
department_idINTEGERReferences departments.department_id
proposal_titleVARCHAR(200)Grant proposal title
grant_reviews
ColumnTypeDescription
review_idPKINTEGERPrimary key for the review
application_idINTEGERReferences grant_applications.application_id
reviewer_nameVARCHAR(120)Reviewer name
scoreNUMERIC(5,2)Review score from 0 to 100
Tablesdepartmentsgrant_applicationsgrant_reviews
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results