1、如果是id自增,按id比较大小取上一条,下一条就行,简单
2、不是id自增,按时间排序的列表数据,用以下sql解决
=====================根据时间排序,查上一条
t_pubservice_content 要查询的表,push_time 为排序的时间字段
select t1.* from( select @num:=@num-2 as rownum, tpc.* from t_pubservice_content tpc,(select @num:=0) as r WHERE tpc.cloumn_id = '1664827884371091458' order by push_time desc ) t1,( select curNum from( select @num2:=@num2-2 as curNum, tpc.* from t_pubservice_content tpc,(select @num2:=0) r2 WHERE tpc.cloumn_id = '1664827884371091458' order by push_time desc ) t where id = '1666995762037964828' )t2 where rownum > curNum order by rownum limit 1
=====================根据时间排序,查上下条
select t1.* from( select @num:=@num+1 as rownum, tpc.* from t_pubservice_content tpc,(select @num:=0) as r WHERE tpc.cloumn_id = '1664827884371091458' order by push_time desc ) t1,( select curNum from( select @num2:=@num2+1 as curNum, tpc.* from t_pubservice_content tpc,(select @num2:=0) r2 WHERE tpc.cloumn_id = '1664827884371091458' order by push_time desc ) t where id = '1666995661924122631' )t2 where rownum > curNum order by rownum limit 1
。
标签:一条,tpc,num2,查上,order,num,mysql,id,select From: https://www.cnblogs.com/spll/p/17623135.html