lundi 12 janvier 2015

How to calculate the columns adding the value of the previous row in SQLite?

What I want to do is, when I select records from the table, the last column is the subtraction of the two columns. Now in the first record, the last column (i.e. Subtraction of two columns) will be [Value1] - [Value2] where `[Value1] and [Value2] are columns of the table.


Now the second record will be like below,



'Value of (previous row.last column) + ([Value1] - [Value2])


and so for the next record and so on.


The columns are as below,



[ID],[Value1],[Value2]


Now the records will be like below,



[ID] [Value1] [Value2] [Result]
1 10 5 10 - 5 = 5
2 15 7 5 + (15 - 7) = 13
3 100 50 13 + (100 - 50) = 63
and so on......

Aucun commentaire:

Enregistrer un commentaire