AD HOC PAGING:
就是指用页面的序号和页面的大小请求一个单独的页面。下面是例子。
DECLARE pagesize AS INT, pagenum AS INT;
SET pagesize = 5;
SET pagenum = 2;
WITH SalesCTE AS
(
SELECT ROW_NUMBER() OVER(ORDER BY qty, empid) AS rownum,
empid, mgrid, qty
FROM dbo.Sales
)
SELECT rownu
比如,我要建立一个1,000,000行的数字表: CREATE TABLE dbo.Nums(n INT NOT NULL PRIMARY KEY); DECLARE max AS INT, rc AS INT; SET max = 1000000; SET rc = 1; INSERT INTO Nums VALUES(1); WHILE rc * 2 <= max BEGIN INSERT INTO dbo.Nums SELECT n + rc FROM dbo.Nums; SET r
SQL2005增加了4个关于队计算的函数:分别是ROW_NUMBER,RANK,DENSE_RANK,NTILE.
注意:这些函数只能出现在SELECT和ORDER BY的查询中。语法如下:
ranking_function over([partition by col_list] order by col_list)
ROW_NUMBER:在排序的基础上对所有列进行连续的数字进行标识。
执行顺序:为了计算列值,优化器首先需要把数据在分区列上进行排序,然后在对这些列进行编码。
SQL