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.
| Author |
Topic |
|
dotnet2010
Starting Member
7 Posts |
Posted - 2011-08-01 : 05:24:01
|
| Hi,I have two values from the same table I want to do a join between the two selects results and show the Id Column and V1-V2The first Select Query Reult from Table T1 Where X groupBy IdID V15 27 119 931 1The Second Select Query Result from Table T2 Where Y GroupBy IdID V25 17 0 19 5I want to show this new table {Id ,(V1-V2) as NewV}Id NewV (V1-V2)5 17 119 4 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-08-01 : 05:28:29
|
[code]select t1.ID, newV = t1.V1 - t2.V2from ( select ID, V1 = sum(V1) from sometable group by ID) t1 inner join ( select ID, V2 = sum(V2) from sometable2 group by ID) t2 on t1.ID = t2.ID[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|