Calculating the SUM of (Quantity*Price) from 2 different tables

前端 未结 5 1778
孤独总比滥情好
孤独总比滥情好 2021-02-04 15:45

I have two tables as follows

PRODUCT table

Id | Name | Price

And an ORDERITEM table

Id | Orde         


        
5条回答
  •  孤街浪徒
    2021-02-04 16:18

    select orderID, sum(subtotal) as order_total from
    (
        select orderID, productID, price, qty, price * qty as subtotal
        from product p inner join orderitem o on p.id = o.productID
        where o.orderID = @orderID
    ) t
    group by orderID
    

提交回复
热议问题