如何将一列数据分为两列 [英] how to separate one column data into two columns

查看:124
本文介绍了如何将一列数据分为两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于如何将一列数据分为两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆