12C SQL-TOP

xuexiaogang發表於2017-11-21
在剛才的基礎上。


insert into look values (2,'a',100);
insert into look values (3,'a',100);
insert into look values (4,'a',100);
insert into look values (5,'a',100);
insert into look values (6,'a',100);
insert into look values (7,'a',100);
insert into look values (8,'a',100);
insert into look values (9,'a',100);
insert into look values (10,'a',100);
insert into look values (11,'a',100);
insert into look values (12,'a',100);
insert into look values (13,'a',100);
insert into look values (14,'a',100);
insert into look values (15,'a',100);
insert into look values (16,'a',100);
insert into look values (17,'a',100);
insert into look values (18,'a',100);
insert into look values (19,'a',100);
insert into look values (20,'a',100);


SELECT * FROM look ORDER BY id DESC FETCH FIRST 3 ROWS ONLY;

SQL> SELECT * FROM look ORDER BY id DESC FETCH FIRST 3 ROWS ONLY;


ID NAME   MONEY
---------- ---------- ----------
20 a     100
19 a     100
18 a     100

排名前三的


SQL> SELECT * FROM look  ORDER BY id DESC FETCH FIRST 10 PERCENT ROWS ONLY;

ID NAME   MONEY
---------- ---------- ----------
20 a     100
19 a     100

排名前10%的

SQL> SELECT * FROM look  ORDER BY id DESC OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY;

ID NAME   MONEY
---------- ---------- ----------
15 a     100
14 a     100
13 a     100
12 a     100
11 a     100
忽略前5條記錄並會顯示錶的下5條記錄:

SELECT * FROM look ORDER BY id FETCH FIRST 5 PERCENT ROWS WITH TIES;  

ID NAME   MONEY
---------- ---------- ----------
1 a     100




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/637517/viewspace-2147547/,如需轉載,請註明出處,否則將追究法律責任。

相關文章