Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Rank Applicants With Window Functions
00:00
5 left

Rank Applicants With Window Functions

EasySQL · PostgreSQL

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
Interviewer

Your question is Rank Applicants With Window Functions. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.