我正在尝试计算我正在处理的项目的免责和无理应用程序的平均值。
这是我当前的查询:
SELECT Count(unexcused) as Unexcused, Count(Points_Assigned) as Excused,
COUNT(Agent_ID) as numAgents
FROM Table1
LEFT JOIN(
SELECT Entry_ID, Points_Assigned FROM Table2
WHERE Points_Assigned = 0
) AS T2 USING(Entry_ID)
LEFT JOIN(
SELECT Entry_ID, Points_Assigned as unexcused FROM Table2
WHERE Points_Assigned > 0
) AS T3 USING(Entry_ID)
LEFT JOIN(
SELECT Employee_ID as Agent_ID FROM Table3
WHERE Team = 1
) AS T4 USING(Agent_ID)
哪个正确导致:
Unexcused | Excused | numAgents
12 | 14 | 69
我想使用numAgents来计算平均每个代理人的免责和无故缺席的平均值。
使用我已有的数据在一个查询中执行此操作的最佳解决方案是什么?
我尝试过(Unexcused / numAgents) AS AverageUnexcused
,但收到错误。
答案 0 :(得分:1)
你得到什么错误?你可以试试
(Count(unexcused)/COUNT(Agent_ID)) AS AverageUnexcused.