出现错误,我试图找出问题所在,但无济于事。请帮助
SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
HAVING COUNT(OrderId) >= 1
答案 0 :(得分:1)
您缺少GROUP BY
:
SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
GROUP BY UserId
HAVING COUNT(OrderId) >= 1
假设OrderId
永远不会是NULL
,则HAVING
是多余的,因此也许就足够了:
SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
GROUP BY UserId;