Search code examples
androidparse-platformcloudnosql

How to retrieve the sum of a column using Parse/Parse Cloud?


I've created an Android application that helps my dad with his daily income/outcome management (for business).

I need an option menu item that when clicked, queries the particular Parse Class for the sum of a certain column (of String type, but data is in numbers only). I had done this using SQLite and it was a piece of cake, but this NoSQL system lacks such basic functions.

I understand we have to use Parse Cloud Code to accomplish this, but I'm not sure on the how-tos as there isn't much documentation on how to use Cloud Code.

Respective Code can be shared on request, as I'm not sure of what block to share. Please help, thank you very much :)


Solution

  • How about after receiving a list from ParseQuery just sum all the rows with for each loop? No need for ParseCloud to my taste.

    Also, You could already make a column of Number type, not String, but let's go with this:

    int sum; //or double or float, whatever needed
    done(List<ParseObject> list, ParseException e){
        for (ParseObject p : list){
            sum += Integer.valueOf(p.getString("yourColumnName"));
        }
    }
    

    Should work like that.