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:

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

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

int sum = 0;
for(int i = 1; i <= gettablerows("GlobalTable1"); i++)
     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.

sachin tandulkar avatar image sachin tandulkar commented ·

@Arun KR Thanks Arun, I already wrote a user command. Just wanted to know whether they have any automatic function.

1 Like 1 ·
sachin tandulkar avatar image sachin tandulkar commented ·

Thankks Matthew. I thought so. I was hoping for something like

totalsum=columnsum("Tablename",range from column).

0 Likes 0 ·
Arun Kr avatar image Arun Kr sachin tandulkar commented ·

Hei Sachin,

You can create a user command for doing this.

Arun KR

1 Like 1 ·
anthony.johnson avatar image
4 Likes"
anthony.johnson answered anthony.johnson edited
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.