0

我有 2 张桌子:

CREATE TABLE employee (
employee_id NUMBER(5),
first_name  VARCHAR2(20),
last_name   VARCHAR2(20),
dept_no     NUMBER(2),
salary      NUMBER(10));

表员工具有值:

(1, 'Dan', 'Morgan', 10, 100000);
(2, 'Helen', 'Lofstrom', 20, 100000);
(3, 'Akiko', 'Toyota', 20, 50000);
(4, 'Jackie', 'Stough', 20, 40000);
(5, 'Richard', 'Foote', 20, 70000);
(6, 'Joe', 'Johnson', 20, 30000);
(7, 'Clark', 'Urling', 20, 90000);

CREATE TABLE bonuses (
employee_id NUMBER, bonus NUMBER DEFAULT 100);

餐桌奖金具有以下价值:

(1,100);
(2,100);
(4,100);
(6,100);
(7,100);

我确实根据奖金表合并:

MERGE INTO bonuses b
USING (
  SELECT employee_id, salary, dept_no
  FROM employee
  WHERE dept_no =20) e
ON (b.employee_id = e.employee_id)
WHEN MATCHED THEN
  UPDATE  SET b.bonus = e.salary * 0.1
  DELETE WHERE (e.salary < 40000)
WHEN NOT MATCHED THEN
  INSERT  (b.employee_id, b.bonus)
  VALUES (e.employee_id, e.salary * 0.05)
  WHERE (e.salary > 40000);

当我从奖金中选择 * 时;

EMPLOYEE_ID BONUS 
------------------
1           100   
2           10000 
3           2500  
4           4000  
5           3500  
7           9000   

我的问题是“employee_id #6 我的奖金记录在哪里”?

4

1 回答 1

0

被声明删除DELETE WHERE (e.salary < 40000)?而且您可能应该使其中一个条件包括平等。毕竟有人的薪水可能只有 40K,就像 Jackie 的一样。

于 2012-10-03T23:20:58.020 回答