分页查询
Sybase不支持limit语法,查询得知SYBASE 12.5.3版本之后,支持了top语法
尝试:
// pageSize:一页的大小;numBefore:前(page-1)的数据条数
select top #{pageSize} *
from table_name
where id not in (select top #{numBefore} *
from table_name
order by id)
出错:
- sybase子查询不支持order by,也不支持top
- top语法后不能接 #{xxx} 这种入参方式,因为 #{xxx}会默认将变量上加上 ‘’
最终:
select top ${pageNum} *
from table_name
order by id
直接取出了前page * pageSize条记录,然后在后端用代码进行分页
因为查到的方法中,有一些是取前page-1页的数据,获得前page-1数据中的最大id,然后再去查询
select top ${pageNum} *
from table_name
where id > #{maxId}
order by id
我感觉一次查询拿出前page页的数据没什么太大差别
还有一种方法是:利用临时表存储在指定记录行数前的数据
但是,这种方法我没成功…