Skip to main content
code fix as per OP edit
Source Link
Madhur Bhaiya
  • 28.9k
  • 10
  • 53
  • 61
  • Use Ifnull() function to replace null values with 0.
  • Use Sum() function to sum both val1 and val2 in a single expression, using Group By on 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 
  • Use Ifnull() function to replace null values with 0.
  • Use Sum() function to sum both val1 and val2 in a single expression, using Group By on source_id.

Do the following:

SELECT resource_id, SUM(IFNULL(val1, 0)) + SUM(IFNULL(val2, 0)) AS total FROM your_table GROUP BY resource_id 
  • Use Ifnull() function to replace null values with 0.
  • Use Sum() function to sum both val1 and val2 in a single expression, using Group By on source_id.

Do the following:

SELECT ressource_id, SUM(IFNULL(val1, 0)) + SUM(IFNULL(val2, 0)) AS total FROM your_table GROUP BY ressource_id 
code fix
Source Link
Madhur Bhaiya
  • 28.9k
  • 10
  • 53
  • 61
  • Use Ifnull() function to replace null values with 0.
  • Use Sum() function to sum both val1 and val2 in a single expression, using Group By on source_id.

Do the following:

SELECT source_idresource_id, SUM(IFNULL(val1, 0)) + SUM(IFNULL(val2, 0)) AS total FROM your_table GROUP BY source_idresource_id 
  • Use Ifnull() function to replace null values with 0.
  • Use Sum() function to sum both val1 and val2 in a single expression, using Group By on source_id.

Do the following:

SELECT source_id, SUM(IFNULL(val1, 0)) + SUM(IFNULL(val2, 0)) AS total FROM your_table GROUP BY source_id 
  • Use Ifnull() function to replace null values with 0.
  • Use Sum() function to sum both val1 and val2 in a single expression, using Group By on source_id.

Do the following:

SELECT resource_id, SUM(IFNULL(val1, 0)) + SUM(IFNULL(val2, 0)) AS total FROM your_table GROUP BY resource_id 
Source Link
Madhur Bhaiya
  • 28.9k
  • 10
  • 53
  • 61

  • Use Ifnull() function to replace null values with 0.
  • Use Sum() function to sum both val1 and val2 in a single expression, using Group By on source_id.

Do the following:

SELECT source_id, SUM(IFNULL(val1, 0)) + SUM(IFNULL(val2, 0)) AS total FROM your_table GROUP BY source_id