I'm having an issue with the subqueries. so i want to list employees whose total hours worked is greater than the average total hours worked with all employee. but with this code, it compares the hours worked for one employee with another each hours by another employee. so this is the summarize: employee total hours worked > average of all employee total hours worked --> WHERE hrs_worked > AVG(SUM(HRS_WORKED)) this is what i want.
SELECT employee.emp_id,
employee.emp_name,
SUM(action.hrs_worked) AS "Total Hours Worked"
FROM action
INNER JOIN allocation ON action.act_id = allocation.act_id
AND action.emp_id = allocation.emp_id
INNER JOIN employee ON allocation.emp_id = employee.emp_id
WHERE action.hrs_worked >
(SELECT AVG(action.hrs_worked)
FROM action)
GROUP BY employee.emp_id,
employee.emp_name
ORDER BY SUM(action.hrs_worked) DESC