I'm supposed to get every departments average wage and only show the department with the highest average wage. I figured out this query, but it doesn't work. Anyone got some ideas?
SELECT department, max(avg(wage))
FROM employees
GROUP BY department;
I get this error: ERROR at line 1: ORA-00937: not a single-group group function
Althogh the queries below show the same result as the other answers, it's nice to show users how it can be done as an alternative:
Looking forward to seeing a custom function for this select also :)
By Googling...
Cause: A SELECT list cannot include both a group function, such as AVG, COUNT, MAX, MIN, SUM, STDDEV, or VARIANCE, and an individual column expression, unless the individual column expression is included in a GROUP BY clause.
Action: Drop either the group function or the individual column expression from the SELECT list or add a GROUP BY clause that includes all individual column expressions listed.
Without CTEs you can do:
With CTEs you could do:
does this work:
(disclaimer: completely untested, so I may have put the rownum bit in the wrong place)