Write a SQL query using window functions to identify the top three highest-yielding manufacturing batches for each fab location over the last quarter.
For this exercise, treat the last quarter as April 1, 2026 through June 30, 2026. Calculate yield as good units divided by tested units, exclude incomplete or invalid yield records, and use batch ID as the tie-breaker.
Output
- One row per selected batch, with
fab_location, batch_id, completed_at, yield_rate, and yield_rank.
- Include no more than three batches per fab location, ordered by location and yield rank.