如何仅在Access查询中的一个字段中选择唯一值

时间:2014-08-14 12:58:46

标签: sql ms-access join ms-access-2007

在向唯一字段显示其他相关数据的同时,我查看了如何使用单个不同列的几个位置。我看到的所有例子都只涉及一个表和一些不适用于我的情况的字段(见下面的代码)。目前我正在使用max函数来缩小所选记录的数量,但它仍然在[Part Group Nbr]列中留下重复项,我只需要具有唯一值。我只需要来自每个[Part Group Nbr]的代表性数据。我还使用SELECT DISTINCT函数完成了一个旁边查询,以获取仅[Part Group Nbr]字段的唯一列表,但我无法找出将其加入查询的任何有意义的方法。

SELECT Reps.[Logistics Rep], Max([Supplier Link].[Supplier Name]) AS [Supplier Name], Max([Supplier Link].[Supplier Nbr]) AS [Supplier Nbr], Max([Part Number].[Loc #]) AS [Loc #], Max([Part Number].[Part Nbr]) AS [Part Nbr], Max([Part Number].[Part Name]) AS [Part Name], Max([Part Number].[Part Group Nbr]) AS [Part Group Nbr], Max([Part Number].[RCM Pack Nbr]) AS [RCM Pack Nbr], Max([Part Number].[Part Status]) AS [Part Status], Max([Part Number].[Project Type]) AS [Project Type], Max([Part Number].[Pack Rank]) AS [Pack Rank], Max([Part Number].[Pack Container]) AS [Pack Container], Max([Part Number].[Pack Quantity]) AS [Pack Quantity], Max(E0.[Drawing Review]) AS [Drawing Review], Max(E0.[Part/Pack Ranking & VSM]) AS [Part/Pack Ranking & VSM], Max(E0.DIS) AS DIS, Max(E0.[Pre Concept]) AS [Pre Concept], Max(E0.[E-0 Status]) AS [E-0 Status], Max(E1.[OEM Impact Study]) AS [OEM Impact Study], Max(E1.[Concept Activity]) AS [Concept Activity], Max(E1.[E-1 Status]) AS [E-1 Status], Max(E2.Prototype) AS Prototype, Max(E2.[NAPS/PIFs]) AS [NAPS/PIFs], Max(E2.[Mass Pro Bid]) AS [Mass Pro Bid], Max(E2.[Mass Pro Selection]) AS [Mass Pro Selection], Max(E2.[PO/Budget Application]) AS [PO/Budget Application], Max(E2.[Quality Confirmation]) AS [Quality Confirmation], Max(E2.[E-2 Status]) AS [E-2 Status], [Part Number].[Base 5], Max(Left([Part Number].[Part Nbr],8)) AS [base 8], Max(Left([Part Number].[Part Nbr],11)) AS [Base 10]

FROM ((((Reps INNER JOIN [Supplier Link] ON Reps.[Logistics Rep] = [Supplier Link].[Logistics Rep]) INNER JOIN [Part Number] ON [Supplier Link].[Supplier Name] = [Part Number].[Supplier Name]) INNER JOIN ([Unique parts List] INNER JOIN E0 ON [Unique parts List].[Part Nbr] = E0.[Part Nbr]) ON [Part Number].[Part Nbr] = [Unique parts List].[Part Nbr]) INNER JOIN E1 ON [Unique parts List].[Part Nbr] = E1.[Part Nbr]) INNER JOIN E2 ON [Unique parts List].[Part Nbr] = E2.[Part Nbr]

WHERE ((([Part Number].[Project Type])="NEW" Or ([Part Number].[Project Type])="MOT" Or ([Part Number].[Project Type])="MOF"))

GROUP BY Reps.[Logistics Rep], [Part Number].[Base 5]

HAVING (((Max([Part Number].[Pack Rank]))="AR" Or (Max([Part Number].[Pack Rank]))="AV" Or (Max([Part Number].[Pack Rank]))="AC" Or (Max([Part Number].[Pack Rank]))="BR" Or (Max([Part Number].[Pack Rank]))="BE" Or (Max([Part Number].[Pack Rank]))="BV"));

0 个答案:

没有答案