2017-06-12 30 views
0

放在我有一个产品表与列车表的productIdPurchaseQuantity列。 什么是根据clientId从购物车表中选择所有productId和PurchaseQuantity的代码(它可以是多个)。之后,特定产品数量将根据购买量减少。 如:产品数量将减少订货时在ASP.net

product table 
productid  Quantity 
    1     10 
    2     20 

cart table 
productId  purchasedQuantity 
    1     5 
    2     3 


now product table will be 
productid  Quantity 
    1     5 
    2     17 

什么将是这个SQL查询?任何解决方案

回答

0
SELECT p.productid, p.Quantity-ct.purchasedQuantity 
from product p 
left join carttable ct 
on p.productid=ct.productid