How to sum column in a table from database

Hello there,

I think it’s easy but I’m a beginner ;).

I try to sum two values coming from fields on my website in a third column called score = gene + frequence which are all numbers and give a score to the personn who made the test.
I tried to add a hook before insert and the code looks like that in data.js :


export function Rongeurs_test_beforeInsert(item, context) {
item.score = item.frequence + item.gene;
return item;
}

Many thanks in advance


Hi Samuel

Check out this post: https://www.wix.com/code/home/forum/community-discussion/trying-to-sum-db-values-with-a-loop

Good luck!
Tiaan

Hi there,

I think this is the exact same challenge I’m facing … did you sort it? …

I’ve added a ‘sum’ column to my dataset called ‘MemberGreenPoints’ as you can see below, and am just wanting to add some code that will automatically add the sum of the ‘Biking Points OandA’, ‘Coffee Cup’, ‘Economic OandA’ and ‘Water Bottle OandA’ values.


I’d really appreciate any help.

Thanks,
Jobbo

teach me pls, i didnt know how to add a ‘sum’