gpt4 book ai didi

SQL 服务器 : multiple WHERE NOT EXISTS clauses

转载 作者:行者123 更新时间:2023-12-05 09:14:34 26 4
gpt4 key购买 nike

我在 Load_Charges_IMPORT 查询中有大约 2600 行未插入到 Load_Charges 查询中。

我试图确保没有添加重复的主键条目。主键在 Load_Charges 查询中建立为复合键(费用说明 + 费用金额)。 Load_Charges_IMPORT 查询中未设置键,此数据是从 excel 文档导入的。

你能告诉我我的代码是否有问题吗?当我知道 Load_Charges_IMPORT< 中有 2600 多行时,为什么我收到 0 row(s) affected 的响应.

INSERT INTO Load_Charges
SELECT *
FROM Load_Charges_IMPORT
WHERE
NOT EXISTS (SELECT [Load ID]
FROM Load_Charges
WHERE Load_Charges_IMPORT.[Load ID] = Load_Charges.[Load ID])
AND NOT EXISTS (SELECT [Charge Description]
FROM Load_Charges
WHERE Load_Charges_IMPORT.[Charge Description] = Load_Charges.[Charge Description])
AND NOT EXISTS (SELECT [Charged Amount]
FROM Load_Charges
WHERE Load_Charges_IMPORT.[Charged Amount] = Load_Charges.[Charged Amount]);

最佳答案

您的 EXISTS 子句排除了任何一个条件为真的所有行,而不仅仅是所有条件都为真的行。试试这个:

INSERT INTO Load_Charges

SELECT *

FROM Load_Charges_IMPORT

WHERE NOT EXISTS (
SELECT *
FROM Load_Charges
WHERE Load_Charges_IMPORT.[Load ID]=Load_Charges.[Load ID]
AND Load_Charges_IMPORT.[Charge Description]=Load_Charges.[Charge Description]
AND Load_Charges_IMPORT.[Charged Amount]=Load_Charges.[Charged Amount]);

关于SQL 服务器 : multiple WHERE NOT EXISTS clauses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53823089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com