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

前端 未结 5 1788
孤独总比滥情好
孤独总比滥情好 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:26

    i think this - including null value = 0

     SELECT oi.id, 
             SUM(nvl(oi.quantity,0) * nvl(p.price,0)) AS total_qty 
        FROM ORDERITEM oi 
        JOIN PRODUCT p ON p.id = oi.productid 
       WHERE oi.orderid = @OrderId 
    GROUP BY oi.id 
    

提交回复
热议问题