简体   繁体   中英

Trouble calculating the sum of a column (type Number) from Parse.com localDatastore?

我的表格和我需要以红色表示的总值

Hi, Could someone please help me with parse.com querying and calculating. I want to calculate the total sum of a column (DEBT) in parse.com from my localDatastore, or from web if first option is not possible. I have tried storing the elements in an array-list but without success. So how do I do that?

Thanks in advance ;)

Parse does not support SUM queries. Here is the official statement .

Anyway, you need to use cloud code or to get all rows to achieve what you want (sadly) client-side.

EDIT

On client-side, make a ParseQuery.findInBackground() request and go through all items, adding values to make the SUM client-side.

new ParseQuery<Whatever>("WHATEVER")
    .findInBackground(new FindCallback<Whatever>() {
        @Override
        public void done(List<Whatever> list, ParseException e) {
            // check for ParseException
            Integer sum = 0;
            for (final Whatever whatever : list) {
                sum += (Integer) whatever.get("Debt");
            }
            // there is your SUM
        }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM