开发者

How to sum price of products in cart per user

开发者 https://www.devze.com 2023-02-06 23:56 出处:网络
I\'m trying to move some logics of my web shop application to database engine, so I figured that counting price of cart would be a good start. So I have a relation shown below with Cart_product table

I'm trying to move some logics of my web shop application to database engine, so I figured that counting price of cart would be a good start. So I have a relation shown below with Cart_product table having foreign keys with Buyer and Product. The total price of cart for each user would 开发者_StackOverflowbe the price of each product in Cart_product multiplied by it's amount. How and with what can I achieve this ? Trigger, procedure, cursor ? Any help appreciated.

How to sum price of products in cart per user


SELECT Buyer_ID, SUM(Amount * Product.ProductPrice)
FROM Cart_product
LEFT JOIN Product on Cart_product.Product_ID = Product.Product_ID
GROUP BY Buyer_ID

would return how much each user's bought. What you do with it from there is up to you.

For a specific user:

SELECT SUM(Amount * Product.ProductPrice)
FROM Cart_product
LEFT JOIN Product on Cart_product.Product_ID = Product.Product_ID
WHERE Buyer_ID = XXX
GROUP BY Buyer_ID
0

精彩评论

暂无评论...
验证码 换一张
取 消