- Use
Ifnull()function to replacenullvalues with 0. - Use
Sum()function to sum both val1 and val2 in a single expression, usingGroup Byon source_id.
Do the following:
SELECT resource_idressource_id, SUM(IFNULL(val1, 0)) + SUM(IFNULL(val2, 0)) AS total FROM your_table GROUP BY resource_idressource_id