Oracle SQL-Error:ORA-00937:不是单组组功能

时间:2013-05-07 02:41:20

标签: sql oracle11g ora-00937

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

我环顾四周,尝试了Group By试图解决这个问题的组合。对不起我的恳求,只是一个可怜的学生。

dnumber和dname来自department表,而salary来自employee表。

1 个答案:

答案 0 :(得分:1)

你的问题不是很清楚..字段来自哪些表?

您需要对3个字段进行子查询,因为它们都需要group by子句

类似

 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

编辑:不知怎的......忘记了我的小组...