Hwo to use sum function in CBL2

Do you have an example of how to get the sum of an integer property for all documents? I can’t find any examples of how to use the aggregation functions.

You’ll want to post to the right category, or maybe one of the admins can move this (ping @czajkowski @matthew.groves @nraboy)

Is your question regarding cbl 2.x?

Yes it is - (and have to fill out to reach 20 chars for a message :slight_smile:)

I don’t know your platform but here is C#


This will give you the sum of all of the values of the “key” path in the database.

Ahh, thanks a lot. I’m using Android, but it looks identical. Sorry for the noob question, but how do I then get the value for a function like that?
I would do a query.execute and get a ResultSet. Would that contain a list of Result with one entry, that I can get with result.getInt(“key”) - or what will the name of the key be?

The key in this case will be autogenerated as $1 I think, but it’s easier to just use getInt(0) to get the integer at “index 0” (the first entry in the result).