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
Msg 8127,Level 16,State 1,Line 11
列“oi.TotalOrderPrice”在ORDER BY子句中无效,因为它不包含在聚合函数或GROUP BY子句中。
答案 0 :(得分:4)
如果您使用GROUP BY
,则只能SELECT
(以及ORDER
)列
MAX()
或COUNT()
)MySQL没有这个限制,但它只是SQL标准的MySQL特定扩展。包含Microsoft SQL的任何其他SQL服务器都具有此功能。