好吧,我可能也已在较早之前发布了此内容,但到目前为止仍找不到答案,因此请帮助我解决这个问题。
我的数据库结构:
ATT (Activity表)
Activity
Emp_ID
Project_ID
Product_ID
New, OnHold, Cancel, Closed
产品表
项目表
员工表
约束条件
Act_ID
Status
现在在我的SQL查询中,我要执行的是负载检查::
Act_ID分配给员工的活动(用表示)由Assigned_To_ID项目(Project_ID中的ATT_Table)和特定状态表示。我需要从我的SQL查询中输出5个值:
Assigned_To_ID
ATT_Table
现在可能有一个条件,假设某个雇员在E1上从事项目P1,P2。所以我的表输出将如下所示:
A B C D E E1 P1 E1 P2
因此,这里的C,D,E将具有与该项目的活动相对应的值(P1或P2)
到目前为止,我已经尝试了::
SELECT F_Name AS A, Project_Name AS B, Count(Act_ID) AS C, Count(Act_ID) AS D FROM Employee_Table, ATT_Table, Project_Table WHERE ATT_table.[Assigned_To_ID] = Employee_Table.[Emp_ID] AND Project_Table.[Project_ID] = ATT_Table.[Project_ID] AND Count(Act_ID) IN (SELECT Count(Act_ID) FROM ATT_Table WHERE ATT_Table.[Status] <> 'Closed' AND ATT_Table.[Status] <> 'OnHold') GROUP BY F_Name, Project_Name;
我正在获取A,B,C。但是,当我尝试查找状态检查活动时,由于该消息提示我无法在WHERE子句中写入计数,因此无法执行该查询。请帮助我这一件事。谢谢..
您提到了Product_Table,但我看不出您的问题如何涉及到该表。对于其余部分,我将从子查询中提取列A,B,C和D,然后在外部查询中计算E。
Product_Table
SELECT sub.F_Name AS A, sub.Project_Name AS B, sub.C, sub.D, ((sub.C / sub.D) * 100) AS E FROM ( SELECT Emp.F_Name, Proj.Project_Name, Count(att.Act_ID) AS C, Sum(IIf(att.Status IN ('New', 'InProcess'), 1, 0)) AS D FROM (ATT_Table AS att INNER JOIN Employee_Table AS Emp ON Emp.Emp_ID = att.Assigned_To_ID) INNER JOIN Project_Table AS Proj ON Proj.Project_ID = att.Project_ID GROUP BY Emp.F_Name, Proj.Project_Name ) AS sub;