gpt4 book ai didi

c# - 为什么我的 SQL 查询返回重复的结果?

转载 作者:太空宇宙 更新时间:2023-11-03 22:18:02 25 4
gpt4 key购买 nike

SQL 如下 - 每个结果出现 3 次而不是一次。

SELECT Consignments.LegacyID, TripDate, CollectionName, DeliveryName, Pallets, Weight, BaseRate, Consignments.FuelSurcharge, AdditionalCharges, BaseRate * Quantity AS 'InvoiceValue', Consignments.Customer, InvoiceNumber,
CASE
WHEN child.LegacyID = Consignments.Customer THEN child.LegacyID
WHEN parent.LegacyID = Consignments.Customer THEN parent.LegacyID
ELSE this.LegacyID
END AS 'InvoiceAcc'
FROM SageAccount this
LEFT JOIN SageAccount parent on parent.LegacyID = this.InvoiceAccount
LEFT JOIN SageAccount child on this.LegacyID = child.InvoiceAccount
JOIN Consignments on (Consignments.Customer = this.LegacyID AND this.Customer = 'True')
OR (Consignments.Customer = parent.LegacyID AND parent.Customer = 'True')
OR (Consignments.Customer = child.LegacyID AND child.Customer = 'True')
WHERE (this.LegacyID = @Customer) AND (TripDate BETWEEN @fromdate AND @todate) AND (InvoiceNumber IS NOT NULL)

SQL 是为另一个类似的查询提供给我的,但这次我修改了它以尝试将它用于我现在正在做的查询,所以我假设我在做一些愚蠢的事情。

非常感谢。

最佳答案

可能是因为您的左联接每个父行有 3 个子行。做一个 select * 来查看你的结果在相乘的行中有什么不同。

关于c# - 为什么我的 SQL 查询返回重复的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4325266/

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