码迷,mamicode.com
首页 > 数据库 > 详细

sql count(1)不要和查询数据混用 非常耗时

时间:2017-11-27 18:46:07      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:select   with   from   next   etc   fetch   alc   pre   code   

count(1)不要和查询数据混用 非常耗时

例子:

SELECT  w.[PKID],
        COUNT(1) OVER() AS TotalCount
FROM w  WITH(NOLOCK)
INNER JOIN  s WITH(NOLOCK)
    ON s.PKID= w.SID
INNER JOIN s2 WITH (NOLOCK)
    ON s2.PKID= w.SID2
INNER JOIN w2 AS WTLWITH(NOLOCK)
    ON W2.WID=w.PKID
ORDER BY w.PKID 
OFFSET 0 ROW FETCH NEXT 15 ROW ONLY

sql count(1)不要和查询数据混用 非常耗时

标签:select   with   from   next   etc   fetch   alc   pre   code   

原文地址:http://www.cnblogs.com/Lulus/p/7905338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!