Can you write a query utilizing SQL window functions to calculate running totals and moving averages for clinical trial enrollment rates?
Use the provided trial and daily enrollment data. Include active trials only, aggregate multiple records for the same trial and date, and calculate rates as enrolled participants divided by screened participants.
trial_name, report_date, total_enrolled, enrollment_rate, running_total_enrolled, and moving_avg_enrollment_rate.trial_name, then report_date ascending.| Column | Type | Description |
|---|---|---|
| trial_idPK | INTEGER | Unique clinical trial identifier |
| trial_name | VARCHAR(50) | Clinical trial name |
| phase | VARCHAR(30) | Clinical development phase |
| status | VARCHAR(40) | Current trial status |
| Column | Type | Description |
|---|---|---|
| enrollment_idPK | INTEGER | Unique enrollment record identifier |
| trial_id | INTEGER | Referenced clinical trial |
| report_date | DATE | Enrollment reporting date |
| enrolled_count | INTEGER | Participants enrolled in the record |
| screened_count | INTEGER | Participants screened in the record |