OK, no answers so here's what I came up with after help from another source:
SELECT COUNT(1)
FROM (
SELECT PupilId AS pupil_id, Max(PeriodId) AS max_period
FROM steph1
WHERE PeriodId <= 100
GROUP BY PupilId
) steph2, steph1
WHERE
PupilId=pupil_id AND
max_period = PeriodId AND
Assessment = 7
Hope that helps somebody else with the same issue.