RATIO_TO_REPORT() over PARTITION
RATIO_TO_REPORT() over PARTITION is a SQL function in the Window Functions category. Calculates the ratio of each value to the total of its partition. Sum of ratios = 1 per partition. The syntax is value / SUM(value) OVER (PARTITION BY grp). It accepts value. It returns ratio per partition. A typical example: SELECT department, name, salary, salary / SUM(salary) OVER (PARTITION BY department) AS salary_ratio FROM employees; -- Each employees salary as fraction of department total -- All ratios in a department sum to 1.0 -- As percentage: ROUND(salary * 100.0 / SUM(salary) OVER (PARTITION BY department), 1) AS pct_of_dept -- Oracle has built-in RATIO_TO_REPORT(): -- RATIO_TO_REPORT(salary) OVER (PARTITION BY department) -- Same result in other DBs with manual calculation A close relative is ROW_NUMBER(), which assigns a unique sequential integer to each row within its partition (1, 2, 3...). A close relative is RANK(), which similar to ROW_NUMBER but gives the same rank to equal values. Leaves gaps in ranking.