2011-06-10 49 views
0

我有以下表格和相關的列。獲取具有日期的行的百分比 - 分組

每個員工可以屬於一個或多個商店。每個商店都在一個組中。

員工

EmployeeId Number 
Certified DateTime 

EmployeeStores

EmployeeStoreId Number 
EmployeeId Number 
StoreId Number 

房屋

StoreId Number 
GroupId Number 

我需要公關請輸入一個查詢,以按組顯示在Employees表中完成的認證 字段的百分比。因此,假設A組, B組,C組,結果集應具備:

Group A 13 
Group B 42 
Group C 21 
Other 24 

這又如何在Access做?

回答

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; 
+0

工作完美。謝謝! – CoderForHire 2011-06-13 16:04:22

+0

請參閱我的回覆 – CoderForHire 2011-06-22 14:06:42