首先,top 5 选出按id排序的前5行数据
之后,top 5 选出按id排序不在前5行id里的数据,即5到10行的数据
1、创建测试表,
create table test_sale(id varchar2(20),sale_num number(10))
2、插入测试数据;
insert into test_sale values('goods_1',15)
insert into test_sale values('goods_2',125)
insert into test_sale values('goods_3',28)
insert into test_sale values('goods_4',36)
insert into test_sale values('goods_5',72)
insert into test_sale values('goods_6',85)
insert into test_sale values('goods_7',99)
insert into test_sale values('goods_8',100)
insert into test_sale values('goods_9',102)
insert into test_sale values('goods_10',35)
commit
3、查询表中全量数据;select t.*, rowid from test_sale t
4、编写语句,查询表中sale_num前5的记录数(前10方案类似);
select * from (select t.*, row_number() over(order by sale_num desc) rn from test_sale t ) t where rn <= 5
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)