Foreach data grouping by value

Certified Associate Developer

Hello, I have the following query: 

Dictionary
  id1(Number (Integer)) 
  currency"USD"(Text)
  createdBy"user1@gmail.com"(Text)
  value 1000 (Number (Decimal))
Dictionary
  id2(Number (Integer))
  currency"USD"(Text)
  createdBy"user1@gmail.com"(Text)
value 2000 (Number (Decimal))
Dictionary
  id3(Number (Integer))
  currency"USD"(Text)
  createdBy"user2@gmail.com"(Text)
 value 2000 (Number (Decimal))

Question is how to foreach this and the result to be grouped by createdBy in this case and the value to be a sum. 

Example result: 

createdby: user1@gmail.com

value: 3000

createdby: user2@gmail.com

value: 2000

  Discussion posts and replies are publicly visible