我正在尝试匹配更新并选择条件相同的查询计数。但是行数却相差很大。
更新查询:
UPDATE MKP set MKP.Quantity = MKP.Quantity + LQD.Quantity, ModifiedDate = GETDATE()
FROM IM_MarketPlace MKP
INNER JOIN IM_ChannelListings CL ON MKP.ListingID = CL.ListingID
INNER JOIN @ListingQuantityData LQD ON LQD.ChanelListingID = RTRIM(LTRIM((CL.ChannelListingID))) and LQD.SalesChannelID = CL.ChannelID
Left outer join IM_ListingVariations LV on LV.ListingCode = RTRIM(LTRIM((LQD.VariationSKU))) and MKP.ListingVariationID = LV.ID and CL.ListingID=LV.ListingID
WHERE MKP.IsActive =1 and MKP.IsDeleted=0 and CL.IsActive =1 and CL.IsDeleted=0
AND (LQD.VariationSKU is null OR (LQD.VariationSKU = LV.ListingCode and lv.ID = MKP.ListingVariationID))
选择查询
select count(mkp.ListingID) FROM IM_MarketPlace MKP
INNER JOIN IM_ChannelListings CL ON MKP.ListingID = CL.ListingID
INNER JOIN @ListingQuantityData LQD ON LQD.ChanelListingID = RTRIM(LTRIM((CL.ChannelListingID))) and LQD.SalesChannelID = CL.ChannelID
Left outer join IM_ListingVariations LV on LV.ListingCode = RTRIM(LTRIM((LQD.VariationSKU))) and MKP.ListingVariationID = LV.ID and CL.ListingID=LV.ListingID
WHERE MKP.IsActive =1 and MKP.IsDeleted=0 and CL.IsActive =1 and CL.IsDeleted=0
AND (LQD.VariationSKU is null OR (LQD.VariationSKU = LV.ListingCode and lv.ID = MKP.ListingVariationID))
为此请帮帮我。
,也请让我知道@@ rowcount如何用于更新查询。
答案 0 :(得分:2)
如果联接中涉及的至少两个表之间存在一对多关系,则会发生这种情况。
SELECT
将计算所有行,包括通过联接相乘的行。 UPDATE
只会计算受IM_MarketPlace
影响的UPDATE
中的唯一行。
在存在一对多关系的情况下,不确定IM_MarketPlace
中连接到特定行的“许多”行中的哪一行被用作该行的更新中的源。