Gyanendra Kumar - 1 year ago 91

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.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

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;
```