Your second table doesn’t look like the lessons table. It looks more like a student catalog but with lessons as a select field. I think you need a lessons table separate from student table. Then have a third table which links them both. The lessons master table has no student data except through linking.
Now in the student table, you need a Linked field to lessons where you can select all lessons that a particular student took. Now you can use this connection to roll up data as you want.
In summary, this has to be solved at table architecture level. And NOT at the tactical roll-up formula level.