I got this Sql Query
declare @ProductNo int
set @ProductNo = 123
select o.OrderNo, OrderDate, ol.Amount
from OrderLine ol
inner join [Order] o on ol.OrderNo = o.OrderNo
where ol.ProductNo = @ProductNo
Now my question is, that I would like to return a sum for each Order.
I tryid changing my query to
select o.OrderNo, OrderDate, ol.Amount,(select sum(ol.Amount * ol.UnitPrice) as OrderTotal from OrderLine oll where oll.OrderNo = o.OrderNo)
from OrderLine ol
inner join [Order] o on ol.OrderNo = o.OrderNo
where ol.ProductNo = @ProductNo
But that’s not running, so I’m hoping someone could help me complete my query
In your sub-select you’re referring to
ol.Amount * ol.UnitPrice, but yourOrderLinetable is calledollin the sub-query, so the following should do: