Write a SQL query to track weekly implementation progress, joining client, project, and usage tables to calculate completion rate and identify at-risk accounts for Commure.
Use active projects and implementation usage from the reporting weeks beginning January 6, January 13, and January 20, 2025. An account is at risk when cumulative completion is below 80% of the expected completion pace.
Output
- One row per active project and reporting week.
- Columns:
client_name, project_name, week_start, weekly_units, cumulative_units, completion_rate, and risk_status.
- Include projects with no usage, show rates as percentages, and order by client name, project name, and week start.
Output details
- Include each active project only from the week containing its
start_date through the week on or before its target_date, inclusively.
- Restrict usage dates to
2025-01-06 inclusive through 2025-01-27 exclusive.
- Represent missing
weekly_units as 0 and calculate cumulative_units from those zero-filled values.
- Round
completion_rate to two decimal places, returning a NULL rate when planned_units is zero.
- Compute expected pace as elapsed project days divided by total project days, clamped between
0 and 1, and compare completion against 80% of that pace.
- Order
client_name, project_name, and week_start ascending.