答案 0 :(得分:1)
将INNER JOIN更改为LEFT JOIN将返回没有订单的客户。
SELECT Customers.CustomerID,
Customers.CompanyName,
COUNT(Orders.OrderID) AS Total
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
GROUP BY Customers.CustomerID,
Customers.CompanyName
此查询返回所有客户(Northwind数据库中为91),对于没有订单的客户,总计显示0。
这是你的追求吗?