sql表有ID TF D1 D2四个字段(D1,D2由任意数字组成)
若D1值与D2值相等,则TF字段的值为2,反之为1
如表所示
ID TF D1 D2 
1  1  10 20  
2  2  5  5 
3  1  7  8
4  2  9  9
...
如何写得出TF的程序

解决方案 »

  1.   

    update tb set TF = 2 where D1 = D2
    update tb set TF = 2 where D1 <> D2
      

  2.   


    update t1 set tf=2 where D1 = D2  
    update t1 set tf=1 where D1 <> D2  
      

  3.   

    --
    update tb set TF=case when D1=D2 then 2 else 1 end
      

  4.   


    update tablea set TF=case when D1=D2 then 2 else 1 end
      

  5.   

    update tablea set TF=case when D1=D2 then TF+1 else TF end
      

  6.   

    update tb set TF=case when D1=D2 then 2 else 1 end
      

  7.   


    update tablea set TF=case when D1=D2 then TF+1 else TF end
      

  8.   

    按照上面大家得方法出现错误:无法绑定由多个部分组成的标识符 "tb.D1"。如何解决
      

  9.   

    update tb set TF=TF+1 where D1=D2 
      

  10.   

    无法绑定由多个部分组成的标识符 "tb.D1"。如何解决