ORA-00937 error during select subquery

Posted by RedRaven on Stack Overflow See other posts from Stack Overflow or by RedRaven
Published on 2012-12-16T04:42:32Z Indexed on 2012/12/16 5:04 UTC
Read the original article Hit count: 166

Filed under:
|

I am attempting to write a query that returns the the number of employees, the average salary, and the number of employees paid below the average.

The query I have so far is:

select trunc(avg(salary)) "Average Pay", 
count(salary) "Total Employees",
(
   select count(salary)
   from employees 
   where salary < (select avg(salary) from employees)
) UnderPaid
from employees;

But when I run this I get the ora-00937 error in the subquery.

I had thought that maybe the "count" function is what is causing the issue, but even running a simpler sub query such as:

select trunc(avg(salary)) "Average Pay", 
count(salary) "Total Employees",
(
  select avg(salary) from employees 
) UnderPaid
from employees;

still returns the same error. As both AVG and COUNT seem to be aggregate functions, I'm not sure why I'm getting the error?

Thanks

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about ora-00937

  • ORA-00937 error during select subquery

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I am attempting to write a query that returns the the number of employees, the average salary, and the number of employees paid below the average. The query I have so far is: select trunc(avg(salary)) "Average Pay", count(salary) "Total Employees", ( select count(salary) from employees … >>> More

  • Maximum of averages

    as seen on Stack Overflow - Search for 'Stack Overflow'
    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:… >>> More