Reputation:
Giving an error, I was trying to see what's wrong, to no avail. Please help
SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
HAVING COUNT(OrderId) >= 1
Upvotes: 0
Views: 723
Reputation: 1269803
You are missing the GROUP BY
:
SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
GROUP BY UserId
HAVING COUNT(OrderId) >= 1
Assuming that OrderId
is never NULL
, the HAVING
is redundant, so perhaps this is sufficient:
SELECT UserId, AVG(Total) AS AvgOrderTotal
FROM Invoices
GROUP BY UserId;
Upvotes: 1