First and Foremost, this is part of an assignment.
I am trying to use the COUNT function as part of a query in relation to the Northwind database. The query should return the CustomerID, CompanyName, and the number of of orders placed for each respective customer.
Of course the first two parts are easy, but I can't get the COUNT function to work properly. The query I have so far is:
SELECT DISTINCT Customers.CustomerID, Customers.CompanyName, COUNT(Customers.CustomerID)
FROM Orders, Customers
WHERE Customers.CustomerID = Orders.CustomerID;
What would be the correct syntax to use COUNT in that fashion? It would look like:
CompanyID | CompanyName | # of orders
1 | Company A | 4
2 | Company B | 3
3 | Company C | 5
All examples thus far have been using the COUNT function by itself, and not part of a more complex query.
GROUP BY.GROUP BYandLEFT JOIN(so that customers with no order show up)