Did you mean something like:
SELECT C.Name AS ClassName, SUM(B.Price) * C.Students AS BookCost
FROM Class AS C INNER JOIN
Books AS B ON C.ID = B.ClassId
WHERE C.ID IN (SELECT ID
FROM Class
WHERE Students >= 31
ORDER BY Students ASC
LIMIT 1)
GROUP BY C.ID;