set rowcount 1
update 货架 set 数量 = 数量 - 卖出数量
where 商品编号 = 卖出的商品编号
and 数量 >= 卖出数量
set rowcount 0
只影响一行记录 就不管是哪个货架撩 不知道行不行
--假设商品与货架的表为table_a,里面有商品编号col_1,货架号col_2,货架库存量col_3
--另外假设商品卖出数量为@qty
select @qty - sum(col_3) from table_a where col_1 = '您已知的商品编号'
不知道是不是您想要的结果
delete 货架表 where 货架 in(select 货架 from 商品表 where 商品编号 = 商品编号)