php - MySQL SUM of row data
one text
Solution:
Do you just want an addition?
select t.*,
valu1 + valu2 + valu3 + valu4 as res
from mytable t
Note that if any of the column has a null
value, the addition returns a null
value as well. You might want to avoid that, so:
select t.*,
coalesce(valu1, 0) + coalesce(valu2, 0) + coalesce(valu3, 0) + coalesce(valu4, 0) as res
from mytable t
Source