2

我有 2 张桌子员工和部门

表格employee
empid
name
salary
location

表格department
deptno
deptname
empid
mangerid

现在我想找到部门方面的最高薪水,然后将它们增加 2000

4

3 回答 3

1

ed:哈我没想到您实际上是要更新行,我以为您只是想检索值。@Ajith Sasidharan 的回答更全面。

您的部门表引用员工表而不是相反似乎很奇怪,但是这应该可以满足您的要求:

SELECT
  d.deptno, 
  d.deptname, 
  max(e.salary+2000)
FROM
  department d
INNER JOIN
  employee e
ON 
  e.empid = d.empid
GROUP BY 
  d.deptno, d.deptname;
于 2012-11-30T04:51:32.353 回答
1
update emp
set sal = sal + 2000
where empid in (
select empid from dept where (deptno,sal) in (
select d.deptno,max(e.sal)
    from emp e,
    dept d
    where e.empid = d.empid
    group by deptno));
于 2012-11-30T04:58:13.403 回答
0
    select e.name,e.salary,d.name as Department 
    from employee e join dept d on e.dept = d.id 
    where (e.salary, e.dept) IN (
      select max(salary), dept 
      from employee join dept on (employee.dept = dept.id)
      group by employee.dept
    );
于 2020-01-03T10:09:23.263 回答