how can i get calculate total sum of field based on grouping

Posted by on 15-Apr-2016 01:44

how can i get calculate total sum of field based on grouping

like in sql select username,sum(filed1) form table group by username.

i have table like this

username field1

ram         3000

sai          1000

ram         6000

sai          5000


ram   9000

sai     6000

All Replies

Posted by Shiva Duriseati on 15-Apr-2016 06:28


Please use the following query in the script component.

function callback(arr){

 for(var i=0;i<arr.length;i++){

//Do Something with arr[i][0] and arr[i][1] (Since we have only two colums Username and Amount)

   alert(arr[i][0]+":"+arr[i][1]);//arr[i][0] is Username and arr[i][1] is Sum of the amount



function process()


  rbf_selectQuery("SELECT Username, SUM(Amount) FROM Object_A GROUP BY Username", 100, callback);


But ,instead of doing this you can still make use of view where you can apply filter logic on any field.



Posted by nagad814 on 16-Apr-2016 09:49

hi shiva

i have 2 object 1.fuldata 2.limitshow

in fulldata object i have like this

name sal

ram   3000

ram   2222

sai    4444

sai   5555

ram 1111

i need to show in 2.limitshow

name sal

ram  7333

sai   9999

in every updation or new entry it(limitshow) shld be update from fulldata 

Posted by Shiva Duriseati on 18-Apr-2016 02:23


Create a trigger of type "Object Script" on FullDate Object. Use the below navigation for creating trigger.

FullDate->Object definition->Trigger->New Trigger->Select Object script.

Under the trigger configuration section include the following code.This will check if the record is already existed in LimitShow object with same name as FullData object.If record already exists then it will update the salary field,if record is not available then a new record is being created.

var isRecordExists=rbv_api.selectNumber("SELECT COUNT(1) FROM LimitShow WHERE name=?",'{!name#text}');

//Update if record in FullData already exists.Otherwise create a new record.
var id=rbv_api.selectNumber("SELECT id FROM LimitShow WHERE name=?",'{!name#text}');
var sumOfSal= rbv_api.selectNumber("SELECT SUM(Salaray) FROM FullData WHERE name=?",'{!name#text}');
rbv_api.updateRecord("LimitShow", id, {'Salary':sumOfSal});
rbv_api.createRecord("LimitShow", {'name':'{!name#text}','Salary':{!Salaray}});

Attaching app.xml for your reference.

Please let me know in case you need any assistance.




Posted by on 19-Apr-2016 00:10

Thank you Shiva. Got it..

This thread is closed