question

sachin tandulkar avatar image
3 Likes"
sachin tandulkar asked anthony.johnson edited

Sum of values in column of a table

Is there a readymade function to get the sum of all the values in a particular column of a table? I can do it with for loop but again, lot of coding. Please let me know.

Choose One
tables
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matthew Gillespie avatar image
3 Likes"
Matthew Gillespie answered sachin tandulkar commented

You can use the query command and use SQL to find the sum:

  1. query("SELECT SUM([Col 1]) FROM GlobalTable1");
  2. int sum = getqueryvalue(1, 1);

But that's about the same amount of coding as a for loop:

  1. int sum = 0;
  2. for(int i = 1; i <= gettablerows("GlobalTable1"); i++)
  3. sum += gettablenum("GlobalTable1", i, 1);
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

anthony.johnson avatar image
4 Likes"
anthony.johnson answered anthony.johnson edited
  1. getdatastat(STAT_SUM, gettablerows("GlobalTable1"), gettablenum("GlobalTable1", count, 1))
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.