Search code examples
sqlsumpjaxdataprovider

Adding up two SUM() statements as a third value


I don't know if the title is descriptive enough, but I have the following query:

SELECT 
    SUM(col_1) AS 'value_1', 
    SUM(col_2) AS 'value_2'

WHERE ...

In this query I would like to add up the two values asa third column so the query would look something similar to:

SELECT 
    SUM(col_1) AS 'value_1', 
    SUM(col_2) AS 'value_2',
    'value_1' + 'value_2' as 'value_3'

WHERE ...

This query above is just illustrative, I'm aware it's incorrect, I tried this particular route.

What would be the best way to do something like this? Can it be before the WHERE clause or maybe somewhere else?

It's important for this to happen in the query, because the result gets passed in a Pjax data provider and must be processed beforehand.


Solution

  • Use SUM(col_1 + col_2) AS value_3