sql中数据查询分页,之前看过好多人写的,通过top N条,再通过not in 前几条,感觉那样做挺麻烦的
其实sql中给提供了一个函数,可以要查寻的多加一列,生成一列有序的行号,就是使用函数,ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN)
row_number()从1开始,为每一条分组记录返回一个数字例子
SELECT TOP 10 *
FROM
(
SELECT top 10 [InstanceName], [UserName], [ReportID],
[TimeStart], [TimeEnd],ROW_NUMBER() OVER (ORDER BY ReportID) AS RowNo
FROM [ExecutionLog]
) AS A
WHERE RowNo > " + pageIndex*10