我要实现的功能是这样的:
有两个表:table1  字段:s1,arf
          table2  字段:ss,sums
现在希望对table1更新数据:
    如果table1.s1=table2.ss那么取对应的这条table2.sums
    table1更新为:table1.arf=table1.arf/table2.sums
我是这样写的:
 update table1 
 set table1.arf=table1.arf/table2.sums 
 where table1.s1 in (select ss from table2)
一运行就报错:说invalid fieldname:sums
什么问题阿

解决方案 »

  1.   

    sums 這個字段是不是輸錯了
    語句好象看不出問題
      

  2.   


    UPDATE table1
        SET a1.arf  = a1.arf / a2.sums
    FROM table1 AS a1, table2 AS a2WHERE a1.s1 = a2.ss
      

  3.   

    where table1.s1 in (select ss from table2)
    改成
    table1.s1=table2.ss
      

  4.   

    update table1 
     set table1.arf=table1.arf/table2.sums 
    from table1,table2
     where table1.s1 in (select ss from table2)
      

  5.   

    不行,加上from后,sums那不报错了,可from有报错了,说是invalid keyword
      

  6.   

    这样更新没有道理啊。
    两个表中都有多个记录。
    arf,sums都有多个,你要取哪条记录中的sums呢?
      

  7.   

    今天我在天河购书中心看到个MM拿着本C++在啃!后来买了本MFC!呵呵~对不起,数据库偶不懂...只是灌水
      

  8.   


    update table1 
     set table1.arf=table1.arf/table2.sums 
     where table1.s1=table2.ss
      

  9.   

    不行啊,还是报这个错invalid field name:sums,改个名试试也不行
    是不是tquery不支持这样的sql呢
    有谁熟悉tquery的sql
      

  10.   

    update table1 
     set table1.arf=table1.arf/a2.sums 
     from
     table2 as a2
     where table1.s1 in (select a2.ss from a2)
      

  11.   

    table1里另建一列
    UPDATE table1
    SET sums=(select sums from table2
    WHERE table1.s1 = table2.Ss)
    解决是解决了,不过效率可不太高,需要临时列,不过试了试也没什么好办法了