MDL-37577 quiz overdue handling: optimise database query

This is the standard trick of adding a redundant WHERE clause to a
subquery to help the database realise that it does not have to inspect
so many rows.