使用单个sql语句更新表中的两个不同工资(值)

时间:2015-07-08 14:52:43

标签: sql oracle11g

我必须使用单个sql查询更新薪水为0的员工的薪水为1000,而不是0乘500。 我们怎么做到这一点。 请建议。

2 个答案:

答案 0 :(得分:0)

You can try following query:-

UPDATE your_table 
SET salary = CASE  WHEN (salary = 0)  THEN salary + 1000   
                  WHEN (salary > 0)  THEN salary + 500 END

Hope this helps you.

答案 1 :(得分:0)

create table emp
(id number,
 sal number
 );

 insert into emp values (1,0);
 insert into emp values (2,10);
 insert into emp values (3,0);
 insert into emp values (4,-1);

update emp
set sal = case when sal = 0 Then 1000
               when sal != 0 Then 500
           END

Second condition put it as !=0 by assuming it can be either greater or less or null Hope this help. Next time show your effort also.