Write a SQL query to measure contract turnaround time by team, including average, median, and month-over-month trend.
Use completed contracts only. Turnaround time is the number of days between submission and completion, and the reporting month is based on the completion date. Use the provided teams and contracts tables.
team_name, report_month, contract_count, avg_turnaround_days, median_turnaround_days, avg_turnaround_days_mom, and avg_turnaround_pct_mom.team_name and reporting month.| Column | Type | Description |
|---|---|---|
| team_idPK | INT | Unique team identifier |
| team_name | VARCHAR(100) | Team name |
| Column | Type | Description |
|---|---|---|
| contract_idPK | INT | Unique contract identifier |
| team_id | INT | Team responsible for the contract |
| submitted_at | DATE | Date the contract was submitted |
| completed_at | DATE | Date the contract was completed |