Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Proportional Query

Author  Topic 

WoodHouse
Posting Yak Master

211 Posts

Posted - 2011-08-10 : 02:57:14
Hi Guys,

I need help from you..we have data like below


Table1

Col1 Col2 col3 values
200908 113 1077149 2
200908 113 184254 1
200908 113 989021 2

Table2

col1 col2 Proportional_Value
200908 113 1

Expected Output
200908 113 1077149 2 0.400000
200908 113 184254 1 0.200000
200908 113 989021 2 0.400000



The Proportional_Value will be Proportionaly distributed based on the table1 column values.

Thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-10 : 04:15:08
[code]
select t1.col1, t1.col2, t1.col3, t1.val, proportional_value * 1.0 * t1.val / sum(t1.val) over()
from Table1 t1
inner join Table2 t2 on t1.col1 = t2.col1
and t1.col2 = t2.col2
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -