在 Oracle SQL 中使用 PERCENT_RANK
Using PERCENT_RANK in Oracle SQL
谁能解释一下 Oracle SQL.
中 Percent_Rank() 背后的数学原理
SELECT ID, principal_disbursed, DUE_DATE, CREDIT_OFFICER,
PERCENT_RANK() OVER (ORDER BY principal_disbursed)
FROM TABLE1
我需要了解后台的计算运行。
id
principal_disbursed
principal_repaid
due_date
repayment_date
credit_officer
1
4
4
12/10/2017
17/10/2017
John
2
4
4
10/11/2018
20/10/2018
Maria
3
7
7
18/08/2017
24/08/2017
Maria
4
0
0
04/08/2017
14/07/2017
Maria
5
0
0
04/08/2017
06/08/2017
John
下面是一个可能会给您提示的示例。我已经删除了日期。
with data(id, principal_disbursed, principal_repaid, credit_officer) as (
select 1, 334, 334,'John' from dual union all
select 2, 184, 184,'Maria' from dual union all
select 3, 417, 417,'Maria' from dual union all
select 4, 500, 500,'Maria' from dual union all
select 5, 250, 250,'John' from dual
)
,cnt as (
select count(*)-1 cnt
from data
)
,one as (
SELECT ID, principal_disbursed, CREDIT_OFFICER
from data
order by principal_disbursed
)
select one.*, case when rownum=1 then 0 else (rownum-1)/(select cnt from cnt) end
from one
;
这与 :
相同
with data(id, principal_disbursed, principal_repaid, credit_officer) as (
select 1, 334, 334,'John' from dual union all
select 2, 184, 184,'Maria' from dual union all
select 3, 417, 417,'Maria' from dual union all
select 4, 500, 500,'Maria' from dual union all
select 5, 250, 250,'John' from dual
)
SELECT ID, principal_disbursed, CREDIT_OFFICER,
PERCENT_RANK() OVER (ORDER BY principal_disbursed)
FROM data
谁能解释一下 Oracle SQL.
中 Percent_Rank() 背后的数学原理SELECT ID, principal_disbursed, DUE_DATE, CREDIT_OFFICER,
PERCENT_RANK() OVER (ORDER BY principal_disbursed)
FROM TABLE1
我需要了解后台的计算运行。
id | principal_disbursed | principal_repaid | due_date | repayment_date | credit_officer |
---|---|---|---|---|---|
1 | 4 | 4 | 12/10/2017 | 17/10/2017 | John |
2 | 4 | 4 | 10/11/2018 | 20/10/2018 | Maria |
3 | 7 | 7 | 18/08/2017 | 24/08/2017 | Maria |
4 | 0 | 0 | 04/08/2017 | 14/07/2017 | Maria |
5 | 0 | 0 | 04/08/2017 | 06/08/2017 | John |
下面是一个可能会给您提示的示例。我已经删除了日期。
with data(id, principal_disbursed, principal_repaid, credit_officer) as (
select 1, 334, 334,'John' from dual union all
select 2, 184, 184,'Maria' from dual union all
select 3, 417, 417,'Maria' from dual union all
select 4, 500, 500,'Maria' from dual union all
select 5, 250, 250,'John' from dual
)
,cnt as (
select count(*)-1 cnt
from data
)
,one as (
SELECT ID, principal_disbursed, CREDIT_OFFICER
from data
order by principal_disbursed
)
select one.*, case when rownum=1 then 0 else (rownum-1)/(select cnt from cnt) end
from one
;
这与 :
相同with data(id, principal_disbursed, principal_repaid, credit_officer) as (
select 1, 334, 334,'John' from dual union all
select 2, 184, 184,'Maria' from dual union all
select 3, 417, 417,'Maria' from dual union all
select 4, 500, 500,'Maria' from dual union all
select 5, 250, 250,'John' from dual
)
SELECT ID, principal_disbursed, CREDIT_OFFICER,
PERCENT_RANK() OVER (ORDER BY principal_disbursed)
FROM data