![b05ff4a5ec89efac20480c540af90a75.png](https://i-blog.csdnimg.cn/blog_migrate/1fb74601486a7966151b2f6b7e44bf42.jpeg)
在开发中,很多公司用的ID为自增的,上一条下一条的获取方法不在此类,一般如
select * from tablename where id
select * from tablename where id>$id order by id asc limit 1; 上一条
公司的商品ID用的是uuid,用以前的方式取上一条下一条的方式已不行 如:id$id
下一条
select * from
( select *, (@i:=@i+1) as rownum from shop_commodity,(select @i:=0) as it order by up_time DESC )
as t1 where rownum =((
select rownum from
(
select *, (@j:=@j+1) as rownum from shop_commodity,(select @j:=0) as it
order by up_time DESC
) as tb
where id = '004b76p5pxv063762910'
) + 1
);
上一条
select * from
( select *, (@i:=@i+1) as rownum from shop_commodity,(select @i:=0) as it order by up_time DESC )
as t1 where rownum =((
select rownum from
(
select *, (@j:=@j+1) as rownum from shop_commodity,(select @j:=0) as it
order by up_time DESC
) as tb
where id = '004b76p5pxv063762910'
) - 1
);
Oracle中有一个伪列rownum,可以在生成查询结果表的时候生成一组递增的序列号。MySQL中没有这个伪列,但是有时候要用,可以用如下方法模拟生成一列自增序号。
sql示例:select (@i:=@i+5) as rownum, surname, personal_name from student, (select @i:=100) as init;
用来增加一例,且 rownum 以100为基础,每一次加5.