删除MS-ACCESS邮件列表中的多个条目

时间:2016-12-27 15:13:15

标签: sql ms-access

我创建了一个列出个人姓名和地址的表格。当前表是一个测试表,还没有实际值。如果表中有多个位于同一地址的个人,我需要一种方法来防止生成邮件标签。我在Stackoverflow上找到了以下代码,但无法正常运行。

SELECT (tMin.First_Name2 + ' and ' + tMax.First_Name2) AS First_Name, tMax.Last_Name2 AS Last_Name, tMax.Address1, tMax.Address2, tMax.City,    tMax.State, tMax.ZipCode, tMax.GroupCount  

FROM  
  (SELECT  Max.First_Name AS First_Name2, Max.Last_Name AS Last_Name2, Address1, Address2, City, State, ZipCode, Count(*)=2    AS GroupCount   
FROM Private_Family_Information_Table         
GROUP BY Address1, Address2, City, State, ZipCode         
Having Count(*) = 2) AS tMax Inner Join         

(Select  Min.First_Name AS First_Name2, Min.Last_Name AS Last_Name2, Address1, Address2, City, State, ZipCode, Count(*) AS GroupCount 
FROM Private_Family_Information_Table 
GROUP BY Address1, Address2, City, State, ZipCode         
Having Count(*) = 2) AS tMin                   

On (tMax.Address1 = tMin.Address1) And 
IIF(IsNull(tMax.Address2), '', tMax.Address2) = IIf(IsNull(tMin.Address2),'', tMin.Address2) And (tMax.City = tMin.City) And (tMax.State = tMin.State) And (tMax.ZipCode = tMin.ZipCode)    
UNION ALL 

SELECT Max(First_Name) As First_Name2, Max(Last_Name) As Last_Name2, Address1, Address2, City, State, ZipCode, Count(*) AS GroupCount  
FROM  Private_Family_Information_Table  
GROUP BY Address1, Address2, City, State, ZipCode Having Count(*) = 1 Or       Count(*) > 2
ORDER BY Last_Name, First_Name, State, CIty, ZipCode;

当我在Access中运行查询时,系统会提示我输入min.First_Name,Max.First_Name等的初始参数。我可以按取消循环遍历它请求参数的所有字段名称。然后查询运行并删除具有重复地址的人员的名字和姓氏;重复地址只打印一次(具有重复地址的记录只打印一次,但没有与地址关联的名称)。仅打印一个地址实例的记录。

有什么想法吗?感谢

0 个答案:

没有答案