为满足条件的另一个 table 中的每一行在另一个 table 中插入一行

Insert a row in another table for each row in another table that meets a criteria

我需要为满足条件的另一个 table CUSTOMER 中的每一行插入一个 table CUSTOMER_NOTES 中的新行。

如果 CUSTOMER table 列 CURRENT 被标记为 1,那么我需要在 CUSTOMER_NOTES table 中插入一个注释,例如 "THIS IS A CURRENT CUSTOMER"。因此,如果当前有 50 个客户(总共有 240 个客户),将有 50 个条目被推入 CUSTOMER_NOTES table,VALUE 为 "THIS IS A CURRENT CUSTOMER"。

假设您的 CUSTOMERCUSTOMER_NOTES 有一列 CUSTOMER_ID:

INSERT INTO CUSTOMER_NOTES(
    CUSTOMER_ID, 
    NOTES
)
SELECT
    CUSTOMER_ID,
    'THIS IS A CURRENT CUSTOMER'
FROM CUSTOMER
WHERE
    [CURRENT] = 1