您需要将
JOINRegions更改为Regions
RIGHT JOIN或将Regions作为
FROM表,然后
JOIN从此处更改为其他表。
我喜欢第二种方法,因为它对我来说似乎更直观。您在这里关心地区,并试图获取有关地区的信息,因此应该在
FROM(IMO)中:
SELECt R.RegionName, COUNT(O.uid)FROM Regions RLEFT OUTER JOIN Customers C ON C.Region = R.uid -- I really don't like this naming conventionLEFT OUTER JOIN Orders O ON O.CustomerID = C.uid AND O.DateOrdered LIKE '7%2011%' -- Is your date really stored as a string? Ugh!WHERe R.RegionName <> 'NULL' AND -- This is VERY bad... R.RegionName <> '' AND R.RegionName <> 'Region 1'GROUP BY R.RegionNameORDER BY R.RegionName



