1

嗨,我有以下数据库架构。

employee (employee-name, street, city)
    works (employee-name, company-name, salary)
    company (company-name, city)
    manages (employee-name, manager-name)

我需要给 First Bank Corporation 的所有经理加薪 10%,除非薪水超过 100,000 美元;在这种情况下,只加薪 3%。

我已经为上述问题写了以下查询。

UPDATE works w, manages m
SET w.salary += (salary * 0.10)
WHERE w.employee-name = m.manager-name
AND w.company-name = ‘First Bank Corporation’

但从查询中可以看出,我没有检查工资大于 100000 美元的情况。谁能告诉我该怎么做?

4

3 回答 3

0
SET w.salary *= case when salary > 1000000 then 1.03 else 1.10 end
于 2013-03-20T09:44:07.280 回答
0

如果我理解正确,如果在加薪后他们没有超过 100K,他们需要加薪 10%,在这种情况下使用这个查询;

UPDATE works w, manages m
SET w.salary += salary * case when salary+salary*0.10 > 1000000 then 0.03 else 0.10 end
WHERE w.employee-name = m.manager-name
AND w.company-name = ‘First Bank Corporation’

如果情况是如果他们目前低于 100K,他们需要加薪 10%,请使用以下方法;

UPDATE works w, manages m
SET w.salary += salary * case when salary > 1000000 then 0.03 else 0.10 end
WHERE w.employee-name = m.manager-name
AND w.company-name = ‘First Bank Corporation’
于 2013-03-20T09:46:10.423 回答
0

您应该添加一个案例陈述

UPDATE works w, manages m
SET w.salary = (CASE
WHEN (w.salary * 0.10) < 100000 THEN w.salary + (salary * 0.10)
ELSE w.salary + (salary * 0.03)
END CASE)
WHERE w.employee-name = m.manager-name
AND w.company-name = ‘First Bank Corporation’
于 2013-03-20T09:46:53.167 回答