Saturday, April 26, 2014

what's wrong with my code?

I think you are looking for the query as follows. Always specify your requirement while posting question.


Check below query.



SELECT TOP 1 e.EmployeeID, (SUM(TotalOrderPrice)*0.1) AS reqTotalOrderPrice, COUNT(o.OrderID) as TotalOrders
FROM Employees e
INNER JOIN Orders o
ON o.EMployeeID = e.EmployeeID
INNER JOIN (SELECT OrderID,SUM((UnitPrice * Quantity) - Discount) AS TotalOrderPrice
FROM [Order Details]
GROUP BY OrderID
)oi
ON oi.OrderID = o.OrderID
GROUP BY e.employeeid
ORDER BY reqTotalOrderPrice DESC,TotalOrders ASC


No comments:

Post a Comment