Search notes:

Oracle SQL: RATIO_TO_REPORT (analytic function)

ratio_to_report is an analytic function that returns a value between 0 and 1 which indicates the weight of a numerical value in respect to the sum of all numerical values in the same partition.
If multiplied by 100, the value of ratio_to_report can be interpreted as percentage. This is demonstrated in the following simple example:
drop table spending;

create table spending (
   item  varchar(50) not null,
   price decimal(5,2)
);

insert into spending values ('Something very expensive', 85.13);
insert into spending values ('Averagely priced'        , 63.18);
insert into spending values ('Way too cheap'           ,  9.99);

select
   item,
   price,
   to_char(
      ratio_to_report(price) over () * 100,
     '99.9'
   ) || '%' as pct
from
   spending
;

-- ITEM                             PRICE PCT
-- --------------------------- ---------- ------
-- Something very expensive         85.13  53.8%
-- Averagely priced                 63.18  39.9%
-- Way too cheap                     9.99   6.3%

drop table spending;
Github repository Oracle-Patterns, path: /SQL/select/analytical_functions/ranking/ratio_to_report/spending.sql

See also

Using the Largest Reminder Method to round percentages so that their sum is 100 percent

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758207383, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/select/analytic/ranking/ratio_to_report/index(69): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78