A表的    B条件查询为:s   12
                    w   -13
                    e   -13
                    d   14
        C条件查询为:s   100
                    w   -100
                    e   -100
                    d   100
怎么样能让这两个结果进行相加   结果为:s   112
                                  w   -113
                                  e   -113
                                  d   114
  并能够合计出 小于0的数据地和  ,如上最终的结果为 -226
  这些实现方法都要为SQL语句
  感激不尽!
    

解决方案 »

  1.   

    select sum(s),sum(w),...,sum(case when s < 0 then s else 0 end + case when w < 0 then w else 0 end =......)
    from ta 
    where  B条件 or C条件
      

  2.   


    select (select Num from t where s=12)+(select num from t where s=112) as Num into # from t
    --
    select * from #
    select sum(case when Num <0 then Num else 0 end ) from #