日期:2014-05-17  浏览次数:20844 次

通过订单细目表shopcart更新商品表product销售量 SQL如何实现
表   :属性
shopcart:   id,productid,count...
product:   id,salecount...

shopcart.productid与product.id对应

怎么实现   将shopcart.count加到与之对应的product.salecount上


另:再加个条件shopcart.orderid   =   onevalue   (常量-要处理的订单值)


------解决方案--------------------
XD, 不知道你是加上原有的还是更新 ...

如果是Add:

update product p
set p.salecount = s.count+p.salecount
where exists (
select s.count
from shopcart s
where s.orderid = &onevalue
and p.id = s.productid
);


如果是update:

update product p
set p.salecount = s.count
where exists (
select s.count
from shopcart s
where s.orderid = &onevalue
and p.id = s.productid
);


------解决方案--------------------
update product p set p.salecount = s.count+p.salecount where exists ( select 1 from shopcart s where p.id = s.productid);

再试试看~~~