Reduces query columns just like in array or collection
queryReduce(query, function(result, row [, currentRow] [, query]){} [, initialVal])
→ returns any
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
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;
},0);
writeOutput(total_fruits);
Expected Result: 50
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.