内部查询如下,可以独立工作
select graduate.univid
from graduate, projectmanager, university
where graduate.empid = projectmanager.mgrid and rownum = 1
group by graduate.univid
order by count(graduate.univid) desc;
但是当作为子查询使用时,ORACLE sqlplus继续给出"缺少右括号"错误
select university.univname
from university
where exists
(
select graduate.univid
from graduate, projectmanager, university
where graduate.empid = projectmanager.mgrid and rownum = 1
group by graduate.univid
order by count(graduate.univid)
);
我已经检查过stackoverflow上的类似问题,但并没有真正帮助
答案 0 :(得分:0)
你使用存在,所以你必须给出大学和子查询的条件。你错过了,你得到错误,我猜错了正确的查询:
select t1.univname
from university t1
where exists
( select 1 from (
select graduate.univid
from graduate, projectmanager, university
where graduate.empid = projectmanager.mgrid and rownum = 1
group by graduate.univid
order by count(graduate.univid)) t2 where t2.univid = t1.univid
);
答案 1 :(得分:0)
假设您的其余逻辑正确,则问题是order by
子句。你应该不在子查询中使用它。
试试这个
select university.univname
from university
where exists
(
select graduate.univid
from graduate, projectmanager, university
where graduate.empid = projectmanager.mgrid and rownum = 1
group by graduate.univid
);
你可以自己尝试一下。
此查询将返回1
select 1 from dual
where exists
(select 2 as id from dual)
但这会失败并给你ORA-00907: missing right parenthesis
select 1 from dual
where exists
(select 2 as id from dual order by id )