sqloracle11gora-00937

Oracle SQL-Error: ORA-00937: not a single-group group function


create or replace view DeptInfo as
select dnumber, dname, AVG(salary), max(salary), min(salary)
from department, employee;

I looked around and tried a combination of Group By's trying to figure this out. Sorry for my pleb-ness, just a measly student.

dnumber and dname are from the department table, while salary is from the employee table.


Solution

  • your question isn't very clear.. what tables are the fields from?

    you will need to have sub queries for your 3 fields, since they all require group by clauses

    something like

     create or replace view DeptInfo as
     SELECT q1.dnumber, 
            q1.dname, 
            q1.AvgSal,
            q2.MaxSal,
            q3.MinSal
     FROM (SELECT dnumber, dname, AVG(salary) as AvgSal 
           FROM department, employee
           GROUP BY dnumber, dname) q1, 
          (SELECT dnumber, dname, MAX(salary) as MaxSal 
           FROM department, employee
           GROUP BY dnumber, dname) q2, 
          (SELECT dnumber, dname, MIN(salary) as MinSal 
           FROM department, employee
           GROUP BY dnumber, dname) q3
     WHERE q1.dnumber = q2.dnumber AND
           q2.dnumber = q3.dnumber AND
           q1.dname = q2.dname AND
           q2.dname = q3.name
    

    edit: somehow... forgot my group bys...