sql分页查询:
select * from
(
select ROW_NUMBER() over(order by 排序条件) as rowNumber,* from [表名] where 条件
) as t
where t.rowNumber>=@firstData and t.rowNumber<=@endData
@firstData代表起始条数,值为(当前页数-1)*每页条数+1;@endData代表结束条数,值为当前页数*每页条数
Access分页查询:(降序查询)
string sql = "";
if (当前页数 == 1)
{
sql = SELECT TOP 每页条数 * FROM [表名] ORDER BY 排序字段 DESC;
}
else
{
sql="select top 每页条数 * from [表名] where 排序字段<(select min(排序字段) from (select top (当前页数-1)*每页条数 排序字段 from [表名] order by 排序字段 desc)) order by 排序字段 desc";
}
//这里排序字段不能有重复数据,可以是Id,addtime等,如果是升序查询,则where后的排序字段>(select max(...........order by 排序字段.......order by 排序字段