0

Im trying to run this query

select customerID, sum(OrderID)
from employee_T
where 2 < select(sum(OrderID) from employee_T)
group by customerID;

I want to list the customer id and the total number of orders placed for every customer that has more than 2 orders.

I get the syntax error on this line

where 2 < select(sum(OrderID) from employee_T)

is it because of the 2?s

1 Answer 1

3

I'm not familiar with ms-access syntax, but this is how you would do that in regular sql:

select customerID, count(OrderID)
from employee_T
group by customerID
having count(orderID) > 2
Sign up to request clarification or add additional context in comments.

1 Comment

having allows the use of aggregate functions like count, because it is applied after the grouping. where filters the rows before they are grouped, having filters them afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.