Average Reviewer Tenure per Grant
Problem
Table: `assignment`
| Column Name | Type |
|---|---|
| grant_id | int |
| reviewer_id | int |
`(grant_id, reviewer_id)` is the primary key. Each row says a reviewer is assigned to a grant proposal.
Table: `reviewer`
| Column Name | Type |
|---|---|
| reviewer_id | int |
| full_name | varchar |
| tenure_years | int |
`reviewer_id` is the primary key; `tenure_years` is never NULL.
For each grant, report the average `tenure_years` across its assigned reviewers, rounded to 2 decimal places, under the alias `avg_tenure`. Return the result in any order.
Tables
Example rows — the live problem includes the full dataset.
| grant_id | reviewer_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| reviewer_id | full_name | tenure_years |
|---|---|---|
| 1 | Mara Voss | 3 |
| 2 | Theo Lin | 2 |
| 3 | Sana Roy | 1 |
Expected output
Your answer should return 2 rows with the columns grant_id, avg_tenure.
Starter code (SQL)
SELECT *
FROM assignment;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock