0

我拼命地越来越努力地完成这件事,但还没有成功。运行此查询时,我得到重复的值。

 select 
    tbl_ShipmentStatus.ShipmentID
    ,Tbl_Contract.ContractID,
    Tbl_Contract.KeyWinCountNumber,
    Tbl_Item.ItemName,
    Tbl_CountryFrom.CountryFromName,
    Tbl_CountryTo.CountryToName,
    Tbl_Brand.BrandName,
    Tbl_Count.CountName,
    Tbl_Seller.SellerName,
    Tbl_Buyer.BuyerName, 
    Tbl_Contract.ContractNumber,
    Tbl_Contract.ContractDate,
    tbl_CountDetail.TotalQty,
    tbl_CostUnit.CostUnitName,
    tbl_Comission.Payment,
    tbl_Port.PortName,
    Tbl_Contract.Vans,
    tbl_Comission.ComissionPay,
    tbl_Comission.ComissionRcv,
    tbl_CountDetail.UnitPrice,
    tbl_Comission.ComissionRemarks,
    tbl_CountDetail.Amount,
    tbl_LCStatus.LCNumber,
    tbl_ShipmentStatus.InvoiceNumber,
    tbl_ShipmentStatus.InvoiceDate,
    tbl_ShipmentStatus.BLNumber,
    tbl_ShipmentStatus.BLDate,
    tbl_ShipmentStatus.VesselName,
    tbl_ShipmentStatus.DueDate
     from tbl_ShipmentStatus 

    inner join tbl_LCStatus
    on
    tbl_LCStatus.LCID = tbl_ShipmentStatus.LCStatusID

    inner join Tbl_Contract
    on
    tbl_LCStatus.ContractID = Tbl_Contract.ContractID 

    inner join Tbl_CountDetail
    on Tbl_Contract.ContractID = Tbl_CountDetail.ContractId

    inner join tbl_Comission
    on
    tbl_Comission.ContractID = Tbl_Contract.ContractID

    inner join Tbl_Item
    on
    Tbl_Item.ItemID = Tbl_Contract.ItemID

    inner join Tbl_Brand
    on Tbl_Brand.BrandID = Tbl_Contract.BrandID
    inner join Tbl_Buyer
    on Tbl_Buyer.BuyerID = Tbl_Contract.BuyerID
    inner join Tbl_Seller
    on Tbl_Seller.SellerID = Tbl_Contract.SellerID
    inner join Tbl_CountryFrom
    on Tbl_CountryFrom.CountryFromID = Tbl_Contract.CountryFromID
    inner join Tbl_CountryTo
    on
    Tbl_CountryTo.CountryToID = Tbl_Contract.CountryToID
    inner join Tbl_Count
    on
    Tbl_Count.CountID = Tbl_CountDetail.CountId
    inner join tbl_CostUnit
    on tbl_Comission.CostUnitID = tbl_CostUnit.CostUnitID
    inner join tbl_Port
    on tbl_Port.PortID = tbl_Comission.PortID

    where tbl_LCStatus.isDeleted = 0
    and tbl_ShipmentStatus.isDeleted =0
    and tbl_LCStatus.isDeleted = 0
    and Tbl_CountDetail.isDeleted = 0
    and Tbl_Contract.isDeleted = 0

    and tbl_ShipmentStatus.LCStatusID = 5

我还附上了我的结果行集的图片。任何关于为什么会发生这种情况的建议都会非常明显。

结果集

4

2 回答 2

1

Typically this happens when you have an implicit partial cross join (Cartesian product) between two of your tables. That's what it looks like to me here.

This happens most often when you have a many-to-many relationship. For example, if a single Album allows both multiple Artists and multiple Songs and the only relationship between Artists and Songs is Album, then there's essentially a many-to-many relationship between Artists and Songs. If you select from all three tables at once you're going to implicitly cross join Artists and Songs, and this may not be what you want.

Looking at your query, I see many-to-many between Tbl_CountDetail and tbl_Comission through Tbl_Contract. Try eliminating one of those joins to test to see if the behavior disappears.

于 2012-12-19T10:21:01.330 回答
0

尝试使用DISTINCT关键字。它应该可以解决您的问题

Select DISTINCT ....

等等,据我所知,您的记录不重复。

然而

注意CountName列和Shipment ID

该组合对于每一行都是唯一的。因此,据我所知,这些值是独一无二的。尝试不选择CountName.

好吧,如果您有不同的行,则不是重复问题。问题是在加入期间发生组合,您不希望它复制结果。

要么不选择CountName,要么您的数据有误。

这些行中只有一个应该为真,无论是 6 与 Count2 还是 6 与 Count1。对于 7 也是如此。事实上,当你不应该这样做时,你得到两者都表明一个逻辑错误

于 2012-12-19T09:29:11.703 回答