当前位置: 代码迷 >> Sql Server >> 求sql 语句优化,该怎么处理
  详细解决方案

求sql 语句优化,该怎么处理

热度:87   发布时间:2016-04-27 12:29:40.0
求sql 语句优化
各位大神,帮忙优化一下这条sql语句,速度太慢了?
select c.EName,p.Id,p.Title,p.AddTime,p.CategoryId,
(case when p.id in (select t.ProductId from Product p left join ProductCertificateItem t on p.Id=t.ProductId where t.CertificateItemId=131) then 1 else 0 end) as flag
from Product p left join Category c on p.CategoryId=c.Id
where c.status=1 and p.status=1 and p.UserId=6001

------解决方案--------------------
SQL code
select c.EName,p.Id,p.Title,p.AddTime,p.CategoryId,case when EXISTS(select 1 from  ProductCertificateItem t WHERE p.Id=t.ProductId AND t.CertificateItemId=131) then 1 else 0 end as flagfrom Product p left join Category c on p.CategoryId=c.Idwhere c.status=1 and p.status=1 and p.UserId=6001
  相关解决方案