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 Records with Window Functions
00:00
5 left

Rank Records with Window Functions

EasySQL · PostgreSQL

Problem

Bristol Myers Squibb clinical operations teams need to compare site enrollment performance across active studies for products such as Opdivo and Eliquis. Write a PostgreSQL query that ranks each participating site within its study.

Requirements

  1. Join the study, site, and enrollment data.
  2. Include only active studies where the site enrollment count is known.
  3. Use RANK() to rank sites separately within each study, with the highest enrollment receiving rank 1. Preserve ties.
  4. Return the results ordered by study and rank, with site ID as a deterministic tie-breaker.

Schema

clinical_trials
ColumnTypeDescription
trial_idPKINTUnique clinical trial identifier
product_nameVARCHAR(100)Bristol Myers Squibb product under study
therapeutic_areaVARCHAR(80)Therapeutic area for the study
statusVARCHAR(20)Current study status
trial_sites
ColumnTypeDescription
site_idPKINTUnique clinical trial site identifier
site_nameVARCHAR(120)Site or institution name
countryVARCHAR(60)Country where the site operates
site_enrollment
ColumnTypeDescription
enrollment_idPKINTUnique enrollment record identifier
trial_idINTReferenced clinical trial
site_idINTReferenced trial site
enrolled_patientsINTNumber of enrolled patients
Tablesclinical_trialstrial_sitessite_enrollment
Interviewer

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