Select A.Field1,(B.Field2-A.Field2) AS Field2 From table1 A, table2 WHERE A.Field1=B.Field1ORSelect A.Field1,(B.Field2-A.Field2) AS Field2 From table1 A INNER JOIN Table2 B ON
A.Field1=B.Field2

解决方案 »

  1.   


    create table #A1(name char(10) null,value int null)
    insert into #A1 
    select 'a',1
    union all
    select 'b',2
    union all
    select 'c',3查询
    select a.name,value=(cast((select b.value from #A2 as b where b.name = a.name)as int)-cast(a.value as int))
    from #A1 a
    create table #A2(name char(10) null,value int null)
    insert into #A2 
    select 'a',4
    union all
    select 'b',4
    union all
    select 'c',4
      

  2.   

    update a set col2=a.col2-b.col2 from table2 a,table1 b where a.col1=b.col1