如何用另一个表列值更新列?

时间:2013-12-31 00:18:40

标签: sql sql-server

我有两个表“basket_products”和“products”。我想用“basket_products”“adet”列更新“products”表的“adet”列。我想更新basket_products.urun = products.urun的行。 我想使用此代码并收到错误:“多部分标识符”basket_products.urun“无法绑定。”

update products
    set adet = adet - (
        select basket_products.adet
            from basket_products
                inner join products
               on products.urun = basket_products.urun) 
   where products.urun = basket_products.urun

怎么了?

1 个答案:

答案 0 :(得分:1)

试试这个:

更新p 设置p.adet = bp.adet 来自产品p     加入basket_products bp         在p.urun = bp.urun