如何解决访问查询中的重复项

时间:2019-01-29 18:42:46

标签: sql ms-access

我有一个查询,该查询应该返回每个人的计数和平均值,但是我得到的是人的重复值。我检查了名称的格式,但不确定为什么仍要重复。

 SELECT 
      AssetScores.Department, AssetScores.Evaluator, (Avg(AssetScores.[Final 
      Score]/100)) AS [Average Score], Count(AssetScores.[Final Score]) AS 
      Completed
 FROM 
      AssetScores
 WHERE 
     (((Month([Date of Review]))=Month(Now())) AND ((Year([Date of 
        Review]))=Year(Now())))
 GROUP BY 
     AssetScores.Department, AssetScores.Evaluator, AssetScores.[date of 
     review];

预期结果:

Department    Evaluator   Average Score     Completed
Collections   Melissa Martinez  1           1
Collections   Qiana Bridges         1           3
Collections   Robert Sutowski   1           1
Profit & Loss     Wanda Tavitas         1           2
Recovery      Pete Rodriguez    1           2
Servicing     Crystal Zamarripa     1          11
Servicing     Richard Paez          1          11
Speciality        Patrick Ryan          0.95            8
Vendor Relations  Monica Garza          0.92           10

当前结果

Department    Evaluator   Average Score     Completed
Collections   Melissa Martinez  1           1
Collections   Qiana Bridges         1           3
Collections   Robert Sutowski   1           1
Profit & Loss     Wanda Tavitas         1           1
Profit & Loss     Wanda Tavitas         1           1
Recovery      Pete Rodriguez    1           2
Servicing     Crystal Zamarripa     1          11
Servicing     Richard Paez          1          11
Speciality        Patrick Ryan          0.95            8
Vendor Relations  Monica Garza          0.95           10
Vendor Relations  Monica Garza          0.90            9

2 个答案:

答案 0 :(得分:1)

您的查询当前在GROUP BY子句中具有3个非聚合字段:

 GROUP BY 
    AssetScores.Department, 
    AssetScores.Evaluator, 
    AssetScores.[date of review]

但是,从您的预期输出来看,您似乎不需要审核日期。我建议将GROUP BY子句更改为:

 GROUP BY 
    AssetScores.Department, 
    AssetScores.Evaluator 

答案 1 :(得分:0)

您的SELECT列表中的列应与GROUP BY中的列相同(当然,聚合函数除外),因此请从GROUP BY中删除最后一列