这用于子查询。但我需要使用join
select first_name,department_id,salary from employees
where (department_id , salary) in (select department_id ,max (salary) as max_sal from employees
group by department_id);
答案 0 :(得分:1)
抱歉,没有子查询,你就无法拥有它。但是,您可以使用联接代替IN
运算符:
SELECT
e.first_name AS first_name,
e.department_id AS department_id,
e.salary AS salary
FROM
employees e
JOIN (
SELECT department_id, MAX(salary) AS salary
FROM employees
GROUP BY department_id
) e_max
ON e.department_id = e_max.department_id AND e.salary = e_max.salary