I thing something similar might help https://dba.stackexchange.com/questions/321376/select-all-records-in-which-the-sum-of-values-are-equal-to-a-specific-value/321377#321377