I’m having really hard time trying to make this work. I have this table :
evid_record
Its named evid_record and I want to sum columns : ‘Kolokvijum teorija’ + ‘Kolokvijum zadaci’ + ‘Aktivnost’ + ‘Prisustvo’ + ‘Seminarski rad’ + Domaci rad’.
And the result should be displayed in ‘Predisp. Obaveza’.
I managed to get it partially work from phpmyadmin/mysql
with this code:
SELECT id
, SUM(teorija + zadaci + akt + pris + semrad + domrad)
FROM evid_record
GROUP
BY id
I get the correct results as you can see in the picture :my result
But I don’t know how should I insert that summed data into my column ‘Predisp. obaveza’. I’m not even sure if I’m on a right way. I found some similar situations people asked, tried to apply them on my project, and it didnt work..
2
Answers
Consider storing data like this:
Keep in mind
SUM
is an aggregate function, it will add the values across all rows. You can simply add the columns together directly.You’re looking for an
UPDATE
statement here, as the data clearly already exists in the table and I don’t believe you’re inserting new/raw data