用列的总和除以找到列的值

问题描述:

我在Netezza数据库中有一个包含以下各列的表

I have a table with the following columns in a Netezza Database

Id  field1  field2      
 1   0.9    sum(field1)/0.9
 2   1.7    sum(field1)/1.7
 3   6.9    sum(field1)/6.9
 4   0.4    sum(field1)/0.4
 5   0.2    sum(field1)/0.2
 6   2.8    sum(field1)/2.8
 7   7.0    sum(field1)/7.0

将生成field2列,并将保留表中所示的值.

The field2 column is to be generated and will hold values as shown in the table.

在此示例中,field1的总和为19.9.

For this example the sum of field1 is 19.9.

field1值也会经常更改.

请帮助查询,该查询将帮助计算field2值,并且这些值也以小数表示,因此需要精确的总和.

Please help with a query that will help calculate the field2 value also the values are in decimals so will want the precise sum.

谢谢

您可以使用 OVER子句.

select Id,
       field1,
       (sum(field1) over() / field1) as field2
from YourTable

SQLFiddle