我是SQL的新手,我正在尝试获得在该员工获得最高工资的部门工作的员工的姓名。
我成功地返回了工资最高的员工,但现在我想与他们的Dno和员工行的其余行执行联合,我该如何做呢?
SELECT DISTINCT Fname, Lname, salary
FROM employee
WHERE Dno = (SELECT Dno FROM employee WHERE MAX(salary));
/*names of employees working in the department where the employee receives the high salary 发布于 2019-12-18 13:09:32
您已经接近了,但您应该检查WHERE子句中的薪水:
SELECT Fname, Lname, salary
FROM employee
WHERE salary = (SELECT MAX(salary) FROM employee);我们也可以在这里使用RANK或ROW_NUMBER,例如
WITH cte AS (
SELECT Fname, Lname, salary, RANK() OVER (ORDER BY salary DESC) rnk
FROM employee
)
SELECT Fname, Lname, salary
FROM cte
WHERE rnk = 1;发布于 2019-12-18 13:10:08
发布于 2019-12-18 13:13:36
您可以像这样嵌套select:
Select * from employee where deoptno in
( Select deptno from empoloyee where salary = (Select max(salary) from employee))https://stackoverflow.com/questions/59385797
复制相似问题