|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help Select Query
i have the table with the following structure and data
Values 1 2 3 4 5 so i want a query to this follows output Values SumVal 1 1 2 3 3 6 4 10 5 15 |
|
#2
|
||||
|
||||
|
What exactly is the second colum of what you want to do? Is it a count of How many? Or does it add all the 1's , all the 2's etc. You need to be more specific.
|
|
#3
|
||||
|
||||
|
Where's the
1 3 6 10 15 coming from??? |
|
#4
|
|||
|
|||
|
with more specific
Quote:
The second column value is when first value of first coloum is selected the sumvalue should be 1 when second value of first column is selected(2) the sumvalue should be sum of selected(2) value and the sum of previous value(1) ie value sumvalue 1 1 2 3 when third value of first column is selected(3) the sumvalue should be sum of selected(3) value and the sum of previous values(1+2) ie 3+1+2=6 when third value of first column is selected(4) the sumvalue should be sum of selected(4) value and the sum of previous values(1+2+3) ie 4+1+2+3=10 and so on |
|
#5
|
|||
|
|||
|
This will do the trick
declare @i integer
set @i=1 create table #test (col1 integer,col2 integer) while @i<10 begin insert into #test (col1) values (@i) set @i=@i+1 end update #test set col2=(select sum(col1) from #test a where a.col1<=#test.col1) select * from #test drop table #test |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Help Select Query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|