Suppose let's assume you have 3 teachers and 9 students. Each teacher associated to 3 students using teacher reference in students list. I used data page's to get results for both teacher and student list.
Step to get teachers list
Inside teachers, write other step to get list of students associated to students. Pass the teacher id to get the number of students associated to teacher.