--> ²âÊÔÊý¾Ý: [ta] if object_id('[ta]') is not null drop table [ta] create table [ta] (id int,ÊýÖµ int,Ëã·¨ varchar(2)) insert into [ta] select 1,10,'¼Ó' union all select 2,20,'¼õ' union all select 3,15,'¼Ó' union all select 4,10,'¼Ó' union all select 5,25,'¼õ'
declare @sql varchar(8000) set @sql='select ' select @sql=@sql+case Ëã·¨ when '¼Ó' then '+' else '-' end +ltrim(ÊýÖµ)from [ta] exec(@sql)
--½á¹û£º -10
SQL code: select sum(case when Ëã·¨ = '¼Ó' then ÊýÖµ else - ÊýÖµ end) from tb