您好我有以下数据库scheema。
employee (employee-name, street, city)
works (employee-name, company-name, salary)
company (company-name, city)
manages (employee-name, manager-name)
我需要找到第一银行公司的所有经理人加薪10%,除非薪水超过10万美元;在这种情况下,只提高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美元时,我不会检查案例。谁能告诉我怎么做?
答案 0 :(得分:0)
SET w.salary *= case when salary > 1000000 then 1.03 else 1.10 end
答案 1 :(得分:0)
如果我理解正确的话,他们需要加薪10%,如果他们没有加倍100K,那么就使用这个查询;
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’
如果案件是他们需要10%加薪,如果他们目前在100K以下,请使用以下内容;
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’
答案 2 :(得分: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’