Multi-table 从子查询混淆中无条件取行

Multi-table unconditional fetching rows from sub-query confusion

INSERT ALL
 INTO sal_history (empid,hiredate,sal)
 VALUES (empid,hiredate,sal)
 INTO mgr_history (empid,mgr,sal)
 VALUES (empid,mgr,sal)
SELECT employee_id AS "EMPID",
       hire_date   AS "HIREDATE",
       salary      AS "SAL",
       manager_id  AS "MGR"
FROM   employees
WHERE  employee_id > 200;

insert into 子句如何知道在整个语句中哪些列select 用于插入多表sal_historymgr_history?如我所见,sal_history 中有 3 列,mgr_history 中有 3 列,但在子查询中有 4.

我知道这个语句是如何工作的,对于子查询中的每一行,"insert_into_clause" 只执行一次,但这不是重点,这只是我对列不了解的一件小事。

每个 INTO 子句指定要为该 table 填充哪些列,匹配的 VALUES 子句指定 来自子查询使用。在这种情况下,子查询使用相同的名称,这可能有点令人困惑;也许你会发现使用不同的别名更清楚:

INSERT ALL
 INTO sal_history (empid,hiredate,sal)
 VALUES (sub_empid,sub_hiredate,sub_sal)
 INTO mgr_history (empid,mgr,sal)
 VALUES (sub_empid,sub_mgr,sub_sal)
SELECT employee_id AS "SUB_EMPID",
       hire_date   AS "SUB_HIREDATE",
       salary      AS "SUB_SAL",
       manager_id  AS "SUB_MGR"
FROM   employees
WHERE  employee_id > 200;

VALUES 子句中使用了所有四个子查询列(别名);每个三个,SUB_EMPIDSUB_SAL(带有我希望澄清的前缀)都出现在两者中。