Reduces query columns just like in array or collection

queryReduce(query, function(result, row [, currentRow] [, query]){} [, initialVal]) → returns any

queryReduce Argument Reference

query query

query to process entries from

callback any

Closure or a function reference that will be called for each of the iteration.

Callback parameters:

  • result*any : The result of the reduce operation after the previous iteration
  • row*struct : A struct with all of the columns for the current iteration
  • currentRow*numeric : The value for the current iteration
  • query*query : A reference of the original query

initialValue any

inital value passed as part of the first closure call

Links more information about queryReduce

Examples sample code invoking the queryReduce function

Sum one query column

fruits = queryNew("fruit,amount",
    	"varchar,integer", [{
    		"fruit": "apples",
    		"amount": 15
    	}, {
    		"fruit": "pineapples",
    		"amount": 3
    	}, {
    		"fruit": "strawberries",
    		"amount": 32
    total_fruits = queryReduce(fruits,function(a,b) {
        return a + b.amount;

Expected Result: 50

Fork me on GitHub