declare @tb table
(
[year] int,num int
)
insert @tb
select 2004,100 union
select 2005,200--查询
select sum(num)
from (
select -num as 'num' from @tb where [year]=2004
union
select num from @tb where [year]=2005
)t/*
-----------
100(所影响的行数为 1 行)
*/
(
[year] int,num int
)
insert @tb
select 2004,100 union
select 2005,200--查询
select sum(num)
from (
select -num as 'num' from @tb where [year]=2004
union
select num from @tb where [year]=2005
)t/*
-----------
100(所影响的行数为 1 行)
*/
from tb