2013-04-02 64 views
1

我在oracle sql上有一個名爲employees的表。我想要做的是返回所有員工的部門編號和最低工資,按 部門編號分組,其最低工資大於部門編號不等於50的那些員工的最低工資 。單行子查詢錯誤

這是我想出了:

select department_id, min(salary) 
from employees where min(salary)>(select min(salary) from employees 
where department_id!=50) 
group by department_id; 

甲骨文是給我的錯誤:ORA-00934:組功能在這裏不允許使用

任何人有任何想法,爲什麼發生這種情況?

回答

2

由於您正在使用聚合函數進行過濾,因此您需要將該代碼放在HAVING子句中。您不能在WHERE子句中使用聚合函數:

select department_id, min(salary) 
from employees 
group by department_id 
having min(salary)>(select min(salary) 
        from employees 
        where department_id!=50) 
+0

拍攝,我什至沒有想到!謝謝一堆! – Yoyoyo