DB/ORACLE

[Oracle]RATIO_TO_REPORT()

yeon.Biju 2020. 4. 14. 11:03

오라클 RATIO_TO_REPORT()

 

RATIO_TO_REPORT()

   - 합계에서 각 row가 차지하는 비율을 구할 때 좋은 것 같다.

 

RATIO_TO_REPORT(expr) OVER(query_partition_clause)

의 형태

 

RATIO_TO_REPORT is an analytic function. It computes the ratio of a value to the sum of a set of values. If expr evaluates to null, then the ratio-to-report value also evaluates to null.

 

The set of values is determined by the query_partion_clause. If you omit that clause, then the ratio-to-report is computed over all rows returned by the query. 

 

You cannot nest analytic functions by using RATIO_TO_REPORT or any other analytic function for expr. However, you can use other built-in function expressions for expr

 

 

 

SQL>

SELECT 
    last_name, 
    salary, 
    RATIO_TO_REPORT(salary) OVER() AS rr
FROM employees    
WHERE job_id ='PU_CLERK'
ORDER BY last_name, salary, rr;