当前位置:首页 » 多媒体相关

一句sql语句问题


二个表  
  1,   货品号   数量......  
        idno       qty1   .....  
  2,   物料号   数量......  
        goodsid       qty2   .....  
  己知表2的物料号有些来自表1的货品号,有些不是  
  现在要求用表2的数据来更新表1   的数据:存在于表2   的物料号表1的货品号的数量加上表2的数量.也就是说,先在表2挑出物料号存在于表1的记录,假如是表3,然后在表1中相对的货品号数量加上表3的数量!  
  我记得可以用一句sql来搞定的,不知道怎么写.还是要用循环?

推荐阅读

  • 国美暗投百万元支持HDV 国产EVD再遇劲敌 [详细内容]
  • 再碰长气王 歌美256MB SF22仅卖299元 [详细内容]
  • 常见实用技巧小集 [详细内容]
  • 15日硬件行情:奔4狂涨内存暴跌 硬盘有降 [详细内容]
  • 集体跳水 三星数码相机齐降还送256M卡 [详细内容]
  • 关于小Z的汉字输入 [详细内容]
  • 海尔电脑瞄准国际化路线 冠名墨尔本老虎队 [详细内容]
  • 网友回答:
    网友:txlicenhe

    怎么又出来个表3?  
      是不是如下:  
       update   a   set   a.qty1   =   a.qty1   +   b.qty2    
                from   表1   a  
                join   表2   b   on   a.idno   =   b.goodsid  
     

    网友:pengdali

    update   表1   set   qty1=表2.qty2   from   表2   where   表1.idno=表2.goodsid

    网友:leftie

    update   表1   set   qty1=表1.qty1+表2.qty2    
      from       表1,表2    
      where     表1.idno=表2.goodsid  
     

    网友:tiny_yan

    update   表1   set   qty1=qty1+(select   qty2   from   表2   a   where   a.goodsid=idno)   where   idno   in   (select   b.idno   from   表1   b,表2   c   where   b.idno=c.goodsid)

    网友:happy_0325

    update   表1   set   qty1=表1.qty1+表2.qty2   from   表2   where   表1.idno=表2.goodsid  
     

    网友:chao778899

    update   表1   set   qty1=表1.qty1+表2.qty2   from   表2   where   表1.idno=表2.goodsid

    网友:crazyfor

    update   表1   set   qty1=表2.qty2   from   表2   where   表1.idno=表2.goodsid

    网友:ada255403

    update   表1   set   qty1=表1.qty1+表2.qty2    
      from   表1   inner   join   表2   on   表1.idno=表2.goodsid    
      where   表1.idno=表2.goodsid

    网友:zjcxc

    update   表1   set   数量=b.数量  
      from   表1   a   inner   join(select   物料号,数量=sum(数量)   from   表2   group   by   物料号)   b   on   a.货品号=b.物料号  
     

    网友:zjcxc

    update   表1   set   数量=a.数量+b.数量  
      from   表1   a   inner   join(select   物料号,数量=sum(数量)   from   表2   group   by   物料号)   b   on   a.货品号=b.物料号  
     

    .

    讨论区

    Login