在SQL Server里没有 MINUS ,可以尝试用 NOT EXISTS()来处理,比如: --SQL1: select colname3 from tabname where colname1='AAA'--SQL2: select colname3 from tabname where colname2='BBB'==>select t.colname3 from tabname t where colname1='AAA' and not exists(select 1 from tabname where colname2='BBB' and colname3=t.colname3)
楼上说的不错!用not in也可以实现! declare @tb1 table (col1 int) insert into @tb1 select 1 union all select 2 union all select 3 union all select 4 declare @tb2 table (col1 int) insert into @tb2 select 1 union all select 2 select * from @tb1 where col1 not in(select col1 from @tb2) select * from @tb1 a where not exists(select 1 from @tb2 b where b.col1 = a.col1 ) /* 3 4 */ /* 3 4 */ 结果一样!
2005: select colname3 from tabname where colname1='AAA' except select colname3 from tabname where colname2='BBB'
楼主是要做减法吗?declare @result_1 decimal(18,2) declare @result_2 decimal(18,2)select @result_1=colA from tab1 where colB='A' select @result_2=colA from tab1 where colB='C'select @result_1-@result_2
--SQL1:
select colname3 from tabname where colname1='AAA'--SQL2:
select colname3 from tabname where colname2='BBB'==>select t.colname3 from tabname t where colname1='AAA' and not exists(select 1 from tabname where colname2='BBB' and colname3=t.colname3)
declare @tb1 table (col1 int)
insert into @tb1 select 1 union all
select 2 union all
select 3 union all
select 4
declare @tb2 table (col1 int)
insert into @tb2 select 1 union all
select 2
select * from @tb1 where col1 not in(select col1 from @tb2)
select * from @tb1 a where not exists(select 1 from @tb2 b where b.col1 = a.col1 )
/*
3
4
*/
/*
3
4
*/
结果一样!
2005:
select colname3 from tabname where colname1='AAA'
except
select colname3 from tabname where colname2='BBB'
declare @result_2 decimal(18,2)select @result_1=colA from tab1 where colB='A'
select @result_2=colA from tab1 where colB='C'select @result_1-@result_2