Rehaan Ahmed

Rehaan Ahmed

  • 1.5k
  • 98
  • 4.9k

join a coloumn showing sum of 2 data together

Feb 28 2019 4:33 AM
SELECT o.ProductID ,
p.ProductName ,
o.unitprice AS UnitCost ,
sum(o.Quantity) AS TotalUnitsSold ,
(sum(o.Quantity)*o.unitprice) AS FinalCost
FROM OrderDetails o
JOIN Products p ON o.ProductID = p.ProductID
GROUP BY o.ProductID ,
p.ProductName ,
o.unitprice
ORDER BY 1

I want one more column aside of Final Cost which gives total of Products, in short for chai it should be 2505.60+11772.00

 
 
EXPECTED o/p
ProductID ProductName UnitCost  TotalUnitsSold FinalCost    Total
1                 Chai              14.40        174                   2505.60       14277.60
1                 Chai              18.00         654                  11772.00     Null

Answers (2)