查询语句里面的FrontCategory实际上就是Category,写的时候没注意改过来。

解决方案 »

  1.   

    “A.CategoryID=B.CategoryID”在这两列上建索引。
    “ParentFrontCategoryID='0'”在这列上建索引。
      

  2.   

    在关联字段都已建索引的前提下,SQL 语句稍改一下:
    ----------------------------------------------------------------------------------
    SELECT 
        A.ProductID,
        A.ProductName,
        A.CategoryID 
    FROM 
        Product A,Category B
    WHERE 
        A.ProductID IN(SELECT TOP 3 ProductID FROM Product WHERE CategoryID=A.CategoryID)
        AND 
        A.CategoryID=B.CategoryID 
        AND 
        EXISTS(SELECT 1 FROM FrontCategory WHERE FrontCategoryID=B.ParentFrontCategoryID AND ParentFrontCategoryID='0')
    ORDER BY 
        A.FrontCategoryID
      

  3.   

    SELECT 
        A.ProductID,
        A.ProductName,
        A.CategoryID 
    FROM 
        Product A,Category B
    WHERE 
        A.ProductID IN(SELECT TOP 3 ProductID FROM Product WHERE CategoryID=A.CategoryID)
        AND 
        A.CategoryID=B.CategoryID 
        AND 
        EXISTS(SELECT 1 FROM FrontCategory WHERE FrontCategoryID=B.ParentFrontCategoryID AND ParentFrontCategoryID='0')
    ORDER BY 
        A.FrontCategoryID