calculate average of a class where students offer different number of subjects
SUM(..)/count(..) is close.  Instead:

SUM(sums) / SUM(counts)


That is, each subtotal (student?) has a sum of the scores and a count of the number of items (subjects)