我有以下表格及相关栏目。
每位员工都可以属于一个或多个商店。每个商店都在一个组中。
员工
EmployeeId Number
Certified DateTime
EmployeeStores
EmployeeStoreId Number
EmployeeId Number
StoreId Number
店铺
StoreId Number
GroupId Number
我需要生成一个显示Certified的百分比的查询 按组在Employees表中完成的字段。所以,假设A组, B组和C组,结果集应该有:
Group A 13
Group B 42
Group C 21
Other 24
如何在Access中完成?
答案 0 :(得分:1)
创建此查询,验证它是否返回正确的值,并将其另存为qryGroupCert_base。
SELECT
d.GroupId,
Sum(d.cert_complete) AS SumOfcert_complete,
Count(d.cert_complete) AS CountOfcert_complete
FROM
[SELECT DISTINCT
s.GroupId,
e.EmployeeID,
IIf(e.Certified Is Null,0,1) AS cert_complete
FROM
(Stores AS s
INNER JOIN EmployeeStores AS es
ON s.StoreId = es.StoreId)
INNER JOIN Employees AS e
ON es.EmployeeId = e.EmployeeID
]. AS d
GROUP BY d.GroupId;
然后构建一个使用qryGroupCert_base作为源的新查询。
SELECT
q.GroupId,
(SumOfcert_complete/CountOfcert_complete) * 100 AS percent_certified
FROM
qryGroupCert_base AS q;