我有一个包含数千条记录的表,我正在使用以下查询在 30 秒内获得结果,但它的工作速度非常慢。我怎样才能做得更好?
WITH cte AS
(select
ROW_NUMBER() OVER(ORDER BY sb.nbofviews desc) AS ROW,
sb.ImageId, sb.LicenceType, sb.ImgCollection, sb.nbofviews,
sb.orientation, sb.shootdate, sd.ImgName, sd.Caption, sd.ImgPath,
sd.ImageType, sd.ImgHoverPath, sc.image_color
from
SearchBrain sb,SearchDetails sd, searchcolors sc
where
sc.Imageid = sd.Imageid
and sb.ImageId = sd.ImageId
and sd.imageid in (select ImageId
from SearchInitial
where Primarykeyword =
(Select top 1 Primary_kwd
from p2_kwdmgmt
where all_kwd = 'man')
intersect
select ImageId
from SearchInitial
where Primarykeyword =
(Select top 1 Primary_kwd
from p2_kwdmgmt
where all_kwd = 'jumping')
intersect
select ImageId
from SearchInitial
where Primarykeyword =
(Select top 1 Primary_kwd
from p2_kwdmgmt
where all_kwd = 'beach')
)
)
SELECT *
FROM cte
WHERE ROW BETWEEN 0 AND 31