两行相加

时间:2019-04-27 22:24:01

标签: sql plsql

输入

A       
-----
 5000      
 4000      
-3000
-2000

输出

A      FEEDBACK
-----  --------
 9000  POSITIVE
-5000  NEGATIVE

他们已经输入了。我需要编写代码以带出输出。

1 个答案:

答案 0 :(得分:1)

我认为该查询应该这样做:

select sum(a) as a, 'POSITIVE' as feedback from t where a >= 0 
union
select sum(a) as a, 'NEGATIVE' as feedback from t where a < 0