Clinical Trials & Research Analytics Path · Mission 9 of 25Medium

Average visit drift by site

Three-table JOIN with NULL-safe AVG. Practice routing through fact-fact joins (visits → enrollments) into a dim, filtering NULLs out of an aggregate, and ranking sites on an operational drift metric.

The Brief

Hannah ReedSite Activation Leadslack-dm

Site management call needs a drift report. For every site, give me the average days_off_schedule across all visits at that site — site_name, avg_drift_days (rounded to 2 decimals), sorted by avg_drift_days DESC. Skip NULL drift values (those are no-shows; visit_type and completion live in different columns and we don't want to mix them in). Path is fact_trial_visits → fact_enrollments (on enrollment_id) → dim_sites (on site_id). The top of the list is where I focus this week's calls.

You'll practice

3-table JOINFact-to-fact bridgeAVG with NULL filter

Tables & columns available

fact_trial_visitsfact7 columns
ColumnTypeKey
visit_idINTPK
enrollment_idINTFK → fact_enrollments
scheduled_dateTEXT
actual_dateTEXT
visit_typeTEXT
completed_flagINT
days_off_scheduleINT
fact_enrollmentsfact8 columns
ColumnTypeKey
enrollment_idINTPK
trial_idINTFK → dim_trials
protocol_idINTFK → dim_protocols
patient_idINTFK → dim_trial_patients
site_idINTFK → dim_sites
enrolled_dateTEXT
statusTEXT
withdrawal_reasonTEXT
dim_sitesdim9 columns
ColumnTypeKey
site_idINTPK
site_nameTEXT
cityTEXT
stateTEXT
regionTEXT
site_typeTEXT
enrollment_capacityINT
pi_nameTEXT
activated_dateTEXT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Visits don't have a direct site FK — they reach the site through the enrollment table. Three-table join: visits → enrollments → sites.

Hint 2

Filter NULL drift values out before averaging (no-shows have NULL drift). AVG ignores NULLs by default, but the explicit filter documents intent and makes the row-count expectation predictable.

Hint 3

Group by site name; round the average to two decimals. Sort by drift descending, with site name as the alphabetic tiebreaker. One row per site.