我想从数据库的A表中取出一个数,然后把这个数和B表中的数相加,结果再放回B表中原来的位置,请问一下这样的一段代码应该怎么写?

解决方案 »

  1.   

    1,先把A表和B表要相加的数取出来相加
    2,修改B表中存放那个数的值为相加后的和
      

  2.   

    update b set b=b+(select a from a);
      

  3.   


    具体来说,是不是写成这样啊?   
    String sql = "update account set last = last() + (select money from moneychange where toaccount = account.getZhanghuId())"
            + " where zhanghuId = " + account.getZhanghuId()
            ;
      

  4.   

    update tableA,tableB set tableB.fieldB=tableA.fieldA+tableB.fieldB where ...;