Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Query With Joins and Grouping

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

Your question is SQL Query With Joins and Grouping. 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

GSK's Veeva Vault CTMS reporting team needs a concise enrollment summary for Phase 3 clinical trials during 2025. Write a PostgreSQL query that combines trial, site, and enrollment data.

Requirements

  1. Use INNER JOIN to connect trials, trial_sites, and enrollments.
  2. Include only Phase 3 enrollments recorded during calendar year 2025.
  3. Group results by trial and country, returning the number of distinct sites and total participants.
  4. Exclude groups with no positive enrollment, then sort by total participants descending, followed by trial name and country ascending.

ORDER BY is the PostgreSQL term for sorting query results.

Schema

trials
ColumnTypeDescription
trial_idPKINTEGERUnique clinical trial identifier
trial_nameVARCHAR(120)GSK clinical trial name
phaseVARCHAR(20)Clinical development phase
therapeutic_areaVARCHAR(80)Therapeutic area associated with the trial
trial_sites
ColumnTypeDescription
site_idPKINTEGERUnique trial site identifier
trial_idINTEGERTrial assigned to the site
countryVARCHAR(60)Country where the site operates
statusVARCHAR(20)Operational status of the site
enrollments
ColumnTypeDescription
enrollment_idPKINTEGERUnique enrollment event identifier
site_idINTEGERSite associated with the enrollment event
enrolled_onDATEDate of the enrollment event
participant_countINTEGERNumber of participants recorded
Tablestrialstrial_sitesenrollments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results