有张数据库a表
商品编码    商品名称    标志    数量      单价       总价     日期
00100       数码相机      0      2        2500       5000    2007-02-01
00200       U盘           0      3        200        600     2007-01-01
00500       U盘           0      1        300        300     2007-01-01b表
商品编码     名称      价格
80199     数码相机     2500
00200       U盘         200现在要b表里的商品编码作为判断条件来更新a表里的标志,a表要实现的结果:
商品编码    商品名称    标志    数量      单价       总价     日期
00100       数码相机      1      2        2500       5000    2007-02-01
00200       U盘           0      3        200        600     2007-01-01
00500       U盘           1      1        300        300     2007-01-01

解决方案 »

  1.   

    update a set 标志=1 from b where a.商品编码=b.商品编码
      

  2.   

    update a
    set 标志=1
    where not exists (
    select 1 from b
    where 商品编码=a.商品编码     
    and 名称=a.商品名称
    )
      

  3.   

    update a set a.标志=1 from a表 a
    where not exists(select 1 from b表 b where a.商品编号=b.商品编号)
      

  4.   

    update a set a.标志=1 from a表 a
    where a.商品编号 not in (select b.商品编号 from b表 b )