SQL语句 case when then
有两个SUM字段,SQL语句大概为
select····
sum(number1),
sum(number2)
from tablename
where`````
现在用case when 再加一个字段 当sum(number1)-sum(number2)>=0时,字段值为 “大于零 +数字(数字值就是 sum(number1)=sum(number2)的值) ” 当sum(number1)-sum(number2)>=0时
字段值为“小于零+数字”
这个字段的SQL怎么写?
------解决方案--------------------
汗,老漏东西
select····
sum(number1),
sum(number2),
case when (sum(number1)-sum(number2)>=0) then '大于零'+convert(varchar(50),(sum(number1)-sum(number2)))
when (sum(number1)-sum(number2)<0) then '小于零'+convert(varchar(50),(sum(number1)-sum(number2)))
else NULL end
from tablename
where`````