Sum string in sql
I want to sum the values of Punten1, Punten 2, Punten 3, Punten4 as common. But I know how to sum the values in a column. But not across the row. Does anyone know how to do this.
SELECT Punten1, Punten2, Punten3, Punten4
Punten1 + Punten 2 + Punten3 + Punten4 as Puntentotaal
FROM puntentotaal
So, I would like to sum the values of Punten1, Punten 2, Punten 3, Punten4 in a new column: puntentotaal thanks!
source to share
SELECT Punten1, Punten2, Punten3, Punten4,
Punten1 + Punten2 + Punten3 + Punten4 as Puntentotaal
FROM puntentotaal;
just an extra comma. I am taking your table as a unique id as a column.
UPDATE puntentotaal AS t1 INNER JOIN puntentotaal AS t2 SET t1.Puntentotaal =
(t2.Punten1 + t2.Punten2 + t2.Punten3 + t2.Punten4) where t1.ID = t2.ID;
This will update the sum of Punten1, Punten 2, Punten 3, Punten4 in the Puntentotaal column on all rows.
source to share
Your question headings are like "sum per line", but what you are trying to achieve is summed across a column.
If you are looking for "sum to row" there is a function called SUM (field_name) that will give you the sum of a specific field for all selected rows, you can use this function with GROUP BY
If you are looking for "sum across column" you are doing it right with the + sign, just add the comma as suggested by @paul.
source to share