前言:
目前小伙伴们对“oracle取第一条和最后一条”大概比较珍视,各位老铁们都需要剖析一些“oracle取第一条和最后一条”的相关文章。那么小编在网络上汇集了一些有关“oracle取第一条和最后一条””的相关知识,希望兄弟们能喜欢,同学们快快来了解一下吧!在开发中,很多公司用的ID为自增的,上一条下一条的获取方法不在此类,一般如
select * from tablename where id<$id order by id des limit 1; 下一条
select * from tablename where id>$id order by id asc limit 1; 上一条
公司的商品ID用的是uuid,用以前的方式取上一条下一条的方式已不行 如:id<$id 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.
标签: #oracle取第一条和最后一条 #oracle 取最新一条