Gyanendra Kumar - 1 year ago 69

SQL Question

A column has some negative values and some positive values. It is required to find the sum of negative numbers and the sum of the positive numbers in two separate columns.

Thanks in advance.

Answer Source

Just use `case`

:

```
select sum(case when val > 0 then val end) as pos_sum,
sum(case when val < 0 then val end) as neg_sum
from t;
```