Summing values into repeatable group (aka "groupingBy")

How to do analytic queries on documents? is a very similiar question I think