Assume that we have a table as below:
Column_name |
1 |
-2 |
3 |
-4 |
5 |
Need to write a query to get sum of the positive values and negative values as below:
Positive_sum | Negative_sum |
9 | -6 |
SELECT CASE WHEN column_name>0 THEN SUM(column_name) END AS positive_sum, CASE WHEN column_name<0 THEN SUM (column_name) END AS negative_sum FROM table;
Please comment if this is useful.