2

I have my Table structure like this ::

ATT_Table : Fields - Act_ID, Assigned_To_ID, Percent_Complete(Integer value)
Act_ID is primary key, Assigned_To_ID is referenced to Emp_ID in Employee_Table.

Employee_Table : Fields - Emp_ID, F_Name. 
Emp_ID is primary key.

Now at a particular point in time, 1 or more activities can be assigned to same person. My goal is write a query to calculate a person's load. I want to count the number of activities assigned to a particular person (can be more than 1) then take the average of their percent_Complete.

For example if person A is assigned A1, A2, A3(Act_ID). Then corresponding (Percent_Complete values addition)/3. Basically an average. In my final query result I want:

Name, Number of activities assigned(Count), load value(Avg). 

How do I this? Do I have to use a nested WHERE IN clause ? Thanks.

4 Answers 4

3
SELECT  MIN(F_Name) Employee_Name ,
        COUNT(1) Activities_Assigned ,
        AVG(Percent_Complete) Load_Value
FROM    ATT_Table a
        INNER JOIN Employee_Table e ON a.Assigned_To_ID = e.Emp_ID
GROUP BY e.Emp_ID
Sign up to request clarification or add additional context in comments.

Comments

2

I may be missing some nuance, but it sounds like you can just: join the tables, group by employee, COUNT and AVG for the load.

Comments

1

try the following:

select Emp_ID, F_Name, count(Act_ID), avg(Percent_Complete)
from ATT_Table, Employee_Table where ATT_Table.Assigned_To_ID = Employee_Table.Emp_ID
group by Emp_ID, F_Name

Comments

0

As Dmitri said, something like

SELECT Employee_Table.F_Name, COUNT(*) AS activities, AVG(Percent_Complete) AS load
FROM ATT_Table JOIN Employee_Table ON ATT_Table.Assigned_to_ID = Employee_Table.Emp_ID
WHERE Employee_Table.Emp_ID = 42
GROUP BY Employee_Table.Emp_ID

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.