1

我创建了以下更新,但性能很差。我觉得可能有一种更简单或更有效的方式来进行查询,而不是我的蛮力尝试。请帮忙。

Update LocalServers 
set MustIPL = 1 
where LocalServerID IN (SELECT distinct olu.LocationID 
                        from OfferLocUpdate olu with (NoLock) 
                        Join LocalServers ls WITH (NOLOCK) on olu.LocationID = ls.LocationID 
                        Join CPE_IncentiveDLBuffer DLB with (NoLock) on olu.OfferID = dlb.OfferID 
                        where 
                             olu.LastSent > IncentiveLastHeard 
                             and CreationDate < dateadd(d, -@Days, getdate()) 
                             and DLB.FileName LIKE '%IDL-A')
4

1 回答 1

1

尝试这个:

    DECLARE @DateNow DATETIME
    SET @DateNow = GETDATE()

    ;WITH cte_DLB (OfferID, [FileName]) AS
    (
        SELECT OfferID, [FileName]
        FROM CPE_IncentiveDLBuffer (NOLOCK)
        WHERE  DLB.[FileName] LIKE '%IDL-A'
    )
    UPDATE 
        LS
    SET 
        LS.MustIPL = 1
    FROM 
        LocalServers LS 
        JOIN OfferLocUpdate OLU (NOLOCK) ON LS.LocalServerID = OLU.LocationID
        JOIN LocalServers ls (NOLOCK) ON OLU.LocationID = LS.LocationID 
        JOIN cte_DLB ON OLU.OfferID = cte_DLB.OfferID
    WHERE 
        OLU.LastSent > IncentiveLastHeard 
        AND CreationDate < dateadd(d, -@Days, @DateNow)

如果您澄清了“IncentiveLastHeard”和“CreationDate”列属于哪个表,这将非常有帮助

于 2013-06-13T07:47:16.720 回答