sql oracle新临时列

时间:2015-05-18 15:00:36

标签: sql oracle

我的SQL输出是这样的:

column1

50
20
30

我的最终结果应该是:

    column1   column1_temp

#1  50        50%
#2  20        20%
#3  30        30%

文字中应该发生什么:

SQL SUM(column1 #1-#3) = 100 (or what ever comes out as result) which is 
100% |  column1 #1 50 from 100 is 50%
        column1 #2 20 from 100 is 20%
        column1 #3 30 from 100 is 30%

1 个答案:

答案 0 :(得分:2)

select column1,
       (column1 / sum(column1) over ()) * 100 as pct
from the_table

您可能希望使用to_char()和/或round()来获取所需的格式,但上面应该会为您提供原始数据。