You can do something with manually overriding select values ββlike this, resulting in a single query that returns all your amounts in the form of fields:
sums = entries.select("sum(a) as a, sum(b) as b, ....").first tv[:a] = sums[:a] tv[:b] = sums[:b]
source share