如何将一列数据分为两列

问题描述:

如何将正值和负值从一列分为两列。

how to separate positive and negative values into two columns from one column.

我有一张表 Employee 带有 Salary 列的正负值。我想像这样提取两列NegSalary和PosSalary:

I have a table Employee with a column Salary that has positive and negative value. I want to extract two column NegSalary and PosSalary like this:

Salary              --->   NegSalary       PosSalary
-1000                       -1000           NULL
 2000                        NULL           2000
 1000                        NULL           1000
 500                         NULL           500


select case when col >= 0 then col else null end as pos,
       case when col  < 0 then col else null end as neg
from your_table

neg

您可以在这里看到-> http://rextester.com/MCAW87762