If the field DiscountAmount is the discount per item, calculating order price with discount should be: Quantity*(ItemPrice-Discount)If the field DiscountAmount is the discount per order line, calculating order price with discount should be (actually you don't need brackets for this): (Quantity*ItemPrice)-DiscountIn the below queries, I assume the field DiscountAmount is the discount per item.1) move the subselect to the root selectselect c.EmailAddress ,count(o.CustomerID) as NumberOfOrders ,sum(oi.Quantity*(oi.ItemPrice-oi.DiscountAmount)) as TotalAmount from Customers as c left outer join Orders as o on o.CustomerID=c.CustomerID left outer join OrderItems as oi on oi.OrderID=o.OrderID group by c.EmailAddress order by TotalAmount
2) having linked the tables like above, it's easypeasyselect c.EmailAddress ,sum(oi.Quantity*oi.ItemPrice) as TotalAmountWithoutDiscount ,sum(oi.Quantity*(oi.ItemPrice-oi.DiscountAmount)) as TotalAmountWithDiscount from Customers as c left outer join Orders as o on o.CustomerID=c.CustomerID left outer join OrderItems as oi on oi.OrderID=o.OrderID group by c.EmailAddress order by TotalAmount