sql - 如何修复访问查询中的重复项
问题描述
我有一个查询应该返回每个人的计数和平均值,但是我得到了人们的重复值。我检查了名称的格式,但不知道为什么我仍然得到重复。
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
解决方案
GROUP BY
您的查询当前在子句中有 3 个非聚合字段:
GROUP BY
AssetScores.Department,
AssetScores.Evaluator,
AssetScores.[date of review]
但是,从您的预期输出来看,您似乎不需要审查日期。我建议将GROUP BY
条款更改为:
GROUP BY
AssetScores.Department,
AssetScores.Evaluator
推荐阅读
- php - 在 wampserver 3 上安装 php 扩展
- distributed-system - 再次使用 ipfs add 失败
- python-3.x - 如何在 selenium python 中使用特定的 Chrome 配置文件
- javascript - 如何为下面的函数编写更高效的代码?
- c - 创建要动态链接的包装库
- go - 以 tz 数据库格式获取系统时区名称
- r - 在粘贴命令中使用下标
- javascript - 添加 Geojson 文件(点)并将其用于草坪分析
- javascript - 如何在另一个对象内的对象内获取键的值
- python - 尝试将文件连接到我的 main.py 文件,给我一个错误