Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
SQL Query With Joins and Grouping
00:00
5 left

SQL Query With Joins and Grouping

MediumSQL · PostgreSQL

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
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.