I am using MySQL classicmodels database. The following query works fine (check out the where clause)
select
customers.customerNumber as 'Customer ID',
customers.customerName as 'Customer Name',
count(orders.orderNumber) as 'Total Orders Placed'
from customers
left join orders on customers.customerNumber = orders.customerNumber
where customers.customerNumber > 200
group by
customers.customerNumber
order by
3 asc
But the following errors lead to an error. The goal is to display only those customers in the resulting rowset that have placed more than three orders. What am I doing wrong?
select
customers.customerNumber as 'Customer ID',
customers.customerName as 'Customer Name',
count(orders.orderNumber) as 'Total Orders Placed'
from customers
left join orders on customers.customerNumber = orders.customerNumber
where count(orders.orderNumber) > 3
group by
customers.customerNumber
order by
3 asc
MySQL error: Error code: 1111. Invalid use of group function
user504674
source
share