I am not sure which DB you are using. You also say that you want to store the difference in different "field"s. I am not sure if by fields, you mean columns or what. Using this below approach, you can get all the results in rows:
Assuming sql server 2005, you can get rownumbers for all the rows using row_number() over(order by id)
and then do a self join.
Code Snippet
select a.col1-b.col1 from
(select col1, row_number() over(order by id) as rowid
from tblData)
a,
(select col1, row_number() over(order by id) as rowid
from tblData)
b
where a.rowid=b.rowid+1
|||My appology for not specifying. Yes it is sql 2005 and it a calculation on the same column. Thanks for the above information.sql
No comments:
Post a Comment