T-SQL: SUM problem involving individual rows

Hi everyone,
I have a table:

Id               Value
1                10
2                20
3                40
4                10

And I want to select the Ids, Values, and the proportion of the total of the values that each individual row comprises.  Perhaps it's best illustrated: I want to do a SELECT that results in this:

Id               Value           Proportion
1                10               0.125  (10 / 80 (which is the sum of the Values column))
2                20               0.25 (20 / 80)
3                40               0.5 (40 / 80)
4                10               0.125 (10 / 80)

What's the simplest SQL that can give me these results?

Thanks!
-Mike
bignisAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
select id, value , value / ( select sum(value) from yourtable)
from yourtable

or:

declare @sum numeric(20,3)
select @sum = sum(value) from yourtable
select id, value , value / @sum from yourtable
0
 
bignisAuthor Commented:
Yup, works for me.
0
All Courses

From novice to tech pro — start learning today.