条件单SQL查询插入

时间:2013-04-25 05:10:14

标签: sql

假设我有一个名为:

的TABLE
 EMP(Eid,Ename,ESalary)

现在我必须编写一个将更新的查询:

if employee's salary >= 20000 then increment 25% else update 15% salary

2 个答案:

答案 0 :(得分:3)

update EMP
   set ESalary = CASE WHEN salary >= 20000
                      THEN salary * 1.25
                      ELSE salary * 1.15
                      END;

答案 1 :(得分:0)

试试这个:

update emp a set esalrary = 
(select (case when esalary >=20000 then esalary+(esalary*25/100) 
else  esalary+(esalary*25/100) end) from emp b where a.eid=b.eid);