2016-02-02 87 views
0

內查詢如下,工作正常獨立甲骨文,添加子查詢

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) 
); 
時缺少右括號

我已經檢查了計算器類似的問題,但並不能真正幫助您使用

+0

你的查詢看起來不正確的各種各樣的原因。它缺少一個連接條件(你應該總是使用顯式的'JOIN')。當您只提取一行時,您正在進行彙總。 –

回答

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 
); 
+0

非常感謝您指出「存在」的要求, – Heresy

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)