为什么两次查询的结果是一样的?(我正在使用北风数据库。)
SELECT ContactTitle
, COUNT(CustomerID) AS NumberOfCustomer
FROM dbo.Customers
WHERE ContactTitle LIKE '%sales%'
GROUP BY ContactTitle
HAVING COUNT(*) >= 5
ORDER BY NumberOfCustomer desc
和
SELECT
DISTINCT ContactTitle
, COUNT(CustomerID) AS NumberOfCustomer
FROM dbo.Customers
WHERE ContactTitle LIKE '%sales%'
GROUP BY ContactTitle
HAVING COUNT(*) >= 5
ORDER BY NumberOfCustomer desc
结果是:
ContactTitle NumberOfCustomer
--------------------- ----------------
Sales Representative 17
Sales Manager 11
Sales Associate 7
Sales Agent 5
以我自己的理解,第二个查询获取不同的标题并计算其记录,所以我希望结果不会是因为每个标题的记录数只有 1。我说的对吗?