您知道如何改进以下 sql 选择查询吗?即使在 sql management studio 中也需要一段时间才能得到结果。所以,当我从网站上调用它时,它需要更长的时间。我获得了前 15 名的结果,但获得结果仍然需要时间。是因为子查询吗?
SELECT top 15 t1.TagId, t1.TagName,
(SELECT COUNT(*) FROM TagsToPost
WHERE TagsToPost.TagId=t1.TagId AND
EXISTS(SELECT * FROM Posts
WHERE PostId=TagsToPost.PostId AND
Posts.Time > '2014-01-01 00:00:00.000' AND
Posts.TimePointId=@TimePointId)) as myCount
FROM Tags as t1
WHERE (SELECT COUNT(*) FROM TagsToPost
WHERE TagsToPost.TagId=t1.TagId AND
EXISTS(SELECT * FROM Posts
WHERE PostId=TagsToPost.PostId AND
Posts.Time > '2014-01-01 00:00:00.000' AND
Posts.TimePointId=@TimePointId))>1
ORDER BY myCount DESC