语法:
1、不包含相同结果
FETCH FIRST 10 PERCENT ROWS ONLY
2、包含相同结果
FETCH FIRST 10 PERCENT ROWS WITH TIES
Connected to Oracle Database 12c Enterprise Edition Release 12.2.0.1.0
Connected as [email protected]:1521/ncbtcrmpdb
SQL> --查询IFS_EPCUST_VALUE_INFO表数据总量
SQL> select count(*) from IFS_EPCUST_VALUE_INFO;
COUNT(*)
----------
36520
SQL> --查询活期金额最少的前10%的行,包括金额相同的行
SQL> select count(*) from(select * from IFS_EPCUST_VALUE_INFO order by current_bal fetch first 10 percent rows with TIES);
COUNT(*)
----------
27594
SQL> --查询活期金额等于0的行数
SQL> select count(*) from IFS_EPCUST_VALUE_INFO where current_bal=0;
COUNT(*)
----------
27594
SQL> --查询活期金额最少的前10%的行,不包括金额相同的行
SQL> select count(*) from( select * from IFS_EPCUST_VALUE_INFO order by current_bal fetch first 10 percent rows only);
COUNT(*)
----------
3652
SQL> --查询活期金额最大的前10行,不包括金额相同的行
SQL> select count(*) from( select * from IFS_EPCUST_VALUE_INFO order by current_bal desc fetch first 10 rows only);
COUNT(*)
----------
10
SQL> --查询活期金额最小的前10行,包括金额相同的行
SQL> select count(*) from( select * from IFS_EPCUST_VALUE_INFO order by current_bal fetch first 10 rows with TIES);
COUNT(*)
----------
27594
SQL>