各位高手
本人輸入
sql_command1 -> result_1
sql_command2 -> result_2 現在要result_1 - result_2 sql應點輸入

解决方案 »

  1.   

    在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)
      

  2.   

    楼上说的不错!用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
    */
    结果一样!
      

  3.   


    2005:
    select colname3 from tabname where colname1='AAA'
    except
    select colname3 from tabname where colname2='BBB'
      

  4.   

    楼主是要做减法吗?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 
      

  5.   

    利用C# dataset中table的关系运算应该也可以实现