id是指当前数据tb_id参数
方法一:
string preSql = "select top 1 * from table where tb_id < " + id + " order by tb_id DESC" string nextSql = "select top 1 * from table where tb_id > " + id + " order by tb_id ASC"
方法二:
string preSql = "select * from [table] where tb_id = (select MAX(tb_id) from [table] where tb_id<"+ id + ")"; string nextSql = "select * from [table] where tb_id = (select MIN(tb_id) from [table] where tb_id>"+ id + ")";
将查询结果union即可。
时间: 2024-10-07 11:48:31