读书人

通过订单细目表shopcart更新商品表pro

发布时间: 2012-03-07 09:13:51 作者: rapoo

通过订单细目表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);

再试试看~~~

读书人网 >oracle

热点推荐