I’m trying to complete this Oracle SQL query with no luck.
“List the department that has the least average cost. (Hint: SELECT MIN(AVG(cost)) is valid as long as no other column is combined in the SELECT statement. You can combine the above as a subquery with another query)”
I’m able to get it to display the Depts with their average cost, but when I try to work in MIN it breaks. This is what I have so far.
SELECT DeptNo, AVG(projcost) FROM projects, clinicians WHERE clinicians.Clinicianno = projects.Clinicianno GROUP BY DeptNo;
That will give me the depts and their AVG, but when I change AVG(projcost) to be MIN(AVG(projcost) it breaks. The hint is to make it a subquery but I can’t figure out how to do that yet. Any help would be much appreciated.
EDITED
Suppose I Have the following department project costs
These project Costs would render the following averages
The minimum average for each department is still the same result set.
EDITED AGAIN
If you really must have Minimum Average for each department then this will work
However you will soon realize that this result set is and will always be the same as
EDITED Once More
To obtain the department with the smallest average project cost