select
Col1,
Col1/sum(Col1) as Fraction
from MyTable
This one will not return the desired result. If I add Gruop by Col1
then it will return a bunch of 1'a in the second column. How can I get around the problem?
Basically I want to treat the sum(Col1)
as constant parameter. I can use with
statement but I want a solution where I don't add another select
statement.
I am using Toad and selecting from an Oracle database
Use SUM
in its analytic form:
select
col1,
col1 / sum(col1) over () fraction
from mytable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.