家庭作业问题:
显示该部门人员的姓氏,部门ID和最低工资
这是我到目前为止所拥有的:
SELECT DISTINCT department_id, min(salary)
FROM employees
GROUP BY department_id;
这有效,但是我的老师希望我们使用子查询,但我不知道该怎么做。
答案 0 :(得分:0)
一种方法是使用not exists
:
select last_name, department_id, salary
from employees e1
where not exists (
select 1
from employees e2
where e1.department_id = e2.department_id
and e1.salary > e2.salary
);
答案 1 :(得分:0)
另一种方法是使用您的初始查询作为子查询与:)
select last_name, department_id, X.salary
from employees e1
join (SELECT department_id, min(salary) as salary
FROM employees
GROUP BY department_id;) X
on e1.department_id = X.department_id;
希望有帮助。