是否可能
表AA
ID_USER PERIOD SALARY overtime overtime_wages bonus
1001 1-MAY-2012 $50 13 $3.5 -
1002 1-MAY-2012 $60 16 $5 -
1001 1-JUN-2012 $50 10 $3.5 -
1002 1-JUN-2012 $60 7 $5 -
如果我想通过以下条款找到奖金的价值:
if overtime * overtime_wages <= $ 15 then $ 5 bonus
if overtime * overtime_wages between $ 15 and $ 20 the bonus $ 7
if overtime * overtime_wages >= $ 20 then $ 10 bonus
如何解决逻辑? 这是我的剧本:
UPDATE "AA" A
SET A.BONUS = ( select (( A.OVERTIME*A.OVERTIME_WAGES)<= $ 15)=$5 or
(( A.OVERTIME*A.OVERTIME_WAGES) between $ 15 and $ 20 )=$7 or
(( A.OVERTIME*A.OVERTIME_WAGES)>= $ 20)=$10
FROM "AA" A )
答案 0 :(得分:0)
我认为您正在寻找case
声明:
UPDATE "AA" A
SET A.BONUS = (case when A.OVERTIME*A.OVERTIME_WAGES <= 15 then 5
when A.OVERTIME*A.OVERTIME_WAGES between 15 and 20 then 7
when A.OVERTIME*A.OVERTIME_WAGES >= 20 then 10
end);
您实际上可以将其简化为:
UPDATE "AA" A
SET A.BONUS = (case when A.OVERTIME*A.OVERTIME_WAGES <= 15 then 5
when A.OVERTIME*A.OVERTIME_WAGES <= 20 then 7
else 10
end);