SELECT TOP 4 p.ProductId,p.ImageUrl,p.tag,b.EnglishName as BrandEnglishName,(b.BrandName+p.productmodel) as BrandNameAndModel
FROM products p,ProductBrand b
WHERE p.BrandId=b.BrandId AND
(p.ProductId IN (SELECT ProductId FROM CustomCategoryOrder WHERE CustomCategoryId=86))
order BY ProductId DESC
居然要25秒,帮忙优化下性能

解决方案 »

  1.   

    try this:SELECT TOP 4 p.ProductId,p.ImageUrl,p.tag,b.EnglishName as BrandEnglishName,(b.BrandName+p.productmodel) as BrandNameAndModel
    FROM products p JOIN ProductBrand b ON p.BrandId=b.BrandId
    JOIN CustomCategoryOrder c ON p.ProductId=c.ProductId
    where c.CustomCategoryId=86
      

  2.   

    忘了order bySELECT TOP 4 p.ProductId,p.ImageUrl,p.tag,b.EnglishName as BrandEnglishName,(b.BrandName+p.productmodel) as BrandNameAndModel
    FROM products p JOIN ProductBrand b ON p.BrandId=b.BrandId
    JOIN CustomCategoryOrder c ON p.ProductId=c.ProductId
    where c.CustomCategoryId=86
    order BY p.ProductId DESC