assume I have a table of this kind:
A B 3
C D 1
E F 2
G H 4
The sum of the last column is 10, and I want the biggest values that sum up to at least 60% of the total value. So, in this case, it will return
G H 4
A B 3
It goes up to 70% but if only the 1st value was selected, it will only go up to 40%. Even though there could be a combination that will return exactly 60%, we want to take the largest numbers.
So, I think I know how to sort the values from biggest to smallest and how to sum up all the values, but I don't know how to then take only lines that sum up to 60%.
I think this gives you the correct result. Need to work with a temporary table though, not sure if this can be avoided.