Access / SQL - 绕过COUNT(区别)

时间:2014-11-03 23:57:19

标签: sql ms-access-2013

我有一个名称和地址表(FirstName,LastName,Address)。我想选择每个地址的人都有多个姓的行。例如,如果John Smith和Jane Brown居住在同一地址。访问不能做SELECT(DISTINCT(LastName))所以我不知道如何解决这个问题。

下面给了我不止一个人的地址,但我不知道从哪里开始。

SELECT FirstName, LastName, Address
FROM List
WHERE (Address) IN 
(SELECT Address FROM List GROUP BY (Address) HAVING COUNT(Address) > 1); 

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

相反,请比较min()max()

SELECT FirstName, LastName, Address
FROM List
WHERE Address IN (SELECT Address FROM List 
                  GROUP BY Address HAVING MIN(LastName) <> MAX(LastName));