0

我有这个带有列的表员工

name | salary
-------------
A    | 5000
B    | 2000
c    | 1000 

另一个表与列一起使用

name| work
---------
A   | w1
A   | w2
A   | w3
B   | w4
B   | w5

我想将每个工作的员工工资提高 100 并且只有在工作数量大于 1 时才更新。任何人都可以帮我解决这个问题。我需要一个 sql 更新查询(没有存储的过程或触发器或游标)。

4

2 回答 2

1

请尝试使用合并语句:

MERGE
INTO    employee
USING   (
        select distinct "name", count(*) over (partition by "name") cnt from works
        )x
ON      (employee."name" = x."name")
WHEN MATCHED THEN
UPDATE
SET     salary = salary+(100*case when cnt=1 then 0 else cnt end);
于 2013-10-15T04:14:22.487 回答
1

here is proper query

update employee as a set salary = salary + 100 * NVL((
    SELECT count(*)
    FROM works as b
    where b.name=a.name
    group by name
    having count(*)>1), 0)
于 2013-10-15T03:55:38.457 回答