You are given manufacturing data for assembly runs across facilities and product lines. Write a PostgreSQL query that returns each facility’s average assembly cycle time for every product line, then ranks facilities within each product line from fastest to slowest using a window function. Only include completed runs, and use the product line name in the final output.
Output details
- Return
product_line_name, facility_name, avg_cycle_time_minutes, and facility_rank in that order.
- Round
avg_cycle_time_minutes to two decimal places for output.
- Exclude completed runs whose
cycle_time_minutes is NULL.
- Rank by the unrounded average cycle time ascending, giving equal averages the same rank.
- Order rows by
product_line_name ascending, facility_rank ascending, then facility_name ascending.