-4

我正在运行以下查询,但它花费的时间太长。有没有办法让它更快或改变查询的编写方式?

请帮忙。

SELECT *
FROM   ProductGroupLocUpdate WITH (nolock)
WHERE  CmStatusFlag > 2
       AND EngineID IN ( 0, 1 )
       AND NOT EXISTS (SELECT DISTINCT APGV.LocationID
                       FROM CM_ST_ActiveProductGroupsView AS APGV WITH(nolock)
                       WHERE APGV.LocationID = ProductGroupLocUpdate.Locationid);
4

1 回答 1

0

尝试使用连接重写查询

SELECT PGLU.* from ProductGroupLocUpdate PGLU WITH (NOLOCK) 
LEFT JOIN CM_ST_ActiveProductGroupsView APGV WITH (NOLOCK) 
        ON PGLU.LocationId = APGV.LocationID
WHERE APGV.LocationID IS NULL AND CmStatusFlag>2 AND EngineID IN (0,1)

根据表中的数据量,检查向 LocationId(在两个表中)、CmStatusFlag 和 EngineID 添加索引

于 2012-11-16T20:26:16.173 回答