知方可补不足~sqlserver中使用ROW_NUMBER进行的快速分页

回到目录

这个在SQL2005之后最见的一种分页方式,也是Linq默认生成的执行分页的方法(skip,take),当然在性能上小数量没有问题,在数据达到百万时会很慢,这是我们要清楚的,有时我们在LINQ环境下也需要分页写SQL,这时如何去分布就成为了一个很不好处

理的问题,所以大叔还是把准备的分页代码贡献一下

DECLARE @pageSize INT ;
DECLARE @pageIndex INT ;
SET @pageSize = 5
SET @pageIndex =2 ;
--第二页,每页显示5条数据
SELECT *
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY CreateDate ASC ) AS 'rowNumber' ,
*
FROM dbo.Task_Info
) AS temp
WHERE rowNumber BETWEEN ( ( ( @pageIndex - 1 ) * @pageSize ) + 1 )
AND ( @pageIndex * @pageSize )

在LINQ环境下使用SQL代码如下

Db.Database.SqlQuery<FighterTaskTotalDTO>("你的代码")

结果

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnUAAABNCAIAAABPIwXqAAAXdElEQVR4nO1dQXLbPA/VhZLJ2qteITPuFbzvIs32u0G8yDSX6K4dnyHLzD/Z+TD6F5ZEEHgAQUeuKRlvOB1HokAAfCBIyqW7vu/7vv/8eF9H+e+//759+7Yyo6LcbAk+R1lcaYG019KBtdutLHRb6NooUeYqwecoiystkDby66rcGiXKJUrwOcriSgukXVd+/fPjobt7/kP+vP9xqHq8qn69W9+2Hcf25Rytpot/fjwQYd9f/10XRrmdog4TGf1I6DlLcDvKxUqBtGng/f1833W1I78vWSg6vHxnfH597LrHt4vZPmN+JZ5qL78S/7q9WRyD0t3fz/cxDEWZv5hD1chkLXyMsApuR7lYsUh7f/dA00Tnzq+YnGfpkFLAy/cz5qY17c6XX+9/PG/HOLy5/DqnCVGiTMU9TCBWz5Nfg9tR6oqZX388b8eU9vr4sH30Umuu/Prxfni667Yvp4njw9Pvi9ou8uufHw/3j9/vu657fEvbRI9vH3QpPcXzmP9PNjMXUEekKyfh3cPTy/Pw4TdptOvorJxuf1HFznLrZ6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2S/DpR0ZlfnTnRt351TKfaRI1RObnQQlRsZHkeHKuZk9zTzSEGlGUBE6j1Cx2zHAK1/WH8KmISiK3OFLH2h6U+UtV0F4rNbTCSNJ94Mqch4VgH1H1oKsMdMeMIcl6Qos3jbKpOP3jiAj7IPEaogp1QcB1yeBWfUR1gS9JTsB1oztuz1q/CAz3qnYKflW41wzbXgak2XlHi9ybXr5SKzvzqzImu96/lnZ9WUWFUNiEEhspLdQ868iv5K5tG4nZRvxhjliIQk/sk0FqUQKt5ohcTQo+BhfevsB/AehFrDvtdCve9f1W8bSrwNZwVpJp/DqAXXHGBuq/0/pVpVXad5TUPn1EdM1S1LsvqSTOKsW36obf8rHar1p6j68n0BcZvMb8W0i1A4/mVU9H3/tUZ3c7vDyfKrmP9Ko2CLCIGH8S3TZ0PqvNxKVwiS5x881/0i/jeoiFQ+AE1Ye644nGGzvT19auuD72E0jZxZ9pp5lmY+lNbi0hBUGd96BHeRn1Usr8SVXzW/WP0pisuwJ/oE0F+0eM6n9sMPss65UwB2C6mvlmyJc6ikzi5DywGDc8wooy9ihKeridXvPMErTXd4QxN51c5ZqpMBq8eijkx/v/r9F/IcPabak238yvuBxF3pXAG+hConPfL9Jch0x6PDGPzrlesztcMJOpVxWBE80ahWMRK7CK5ZVYjPFUTjpNGuRT4Aub6/694CQUeU+ktH1SoMt7LFwJl15m0wZrLlrI6BVuwCUyewhZ2BzqAWeEcRnAvihSnCVeCxRW/Hfpf5MK0ZedXm4qCHYjEpu5xflMgsBgEnwOLQwukbfv8psVilUYFbhbB58Di0AJpI79eBKs0KnCzCD4HFocWSBv59SJYpVGBm0XwObA4tEDayK8XwSqNCtwsgs+BxaEF0jaRX6NEiRIlSpQo85buKuk9EAgEAoF1I/JrIBAIBALz4/9+kjrAf9h/ZgAAAABJRU5ErkJggg==" alt="" />

回到目录

上一篇:codeforces 360 D - Remainders Game


下一篇:Hadoop 2.x 生态系统及技术架构图