I have a table:
quiz userid attempt grade
1 3 1 33
2 3 1 67
1 3 2 90
10 3 4 20
2 3
First you need to select just the two rows with highest attempts, which is what the subquery does, then average the grades from the derived table.
SELECT
AVG(grade)
FROM (
SELECT
grade
FROM
`table`
ORDER BY attempt DESC
LIMIT 2
) t;
This will give you a result of 55.0000, which is the average of 90 and 20, the grades for the last two attempts.