SELECT TOP 1 e.EmployeeID
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 TotalOrderPrice * 0.1 DESC,COUNT(o.OrderID) ASC
it gives error likes this:
Msg 8127, Level 16, State 1, Line 11
Column "oi.TotalOrderPrice" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
No comments:
Post a Comment