sql server - Sql Calculating history from migrated data -


I have some data like below

 Table with some sample data

The problem is, I count the history based on the number assuming that the number" submission form "Has a unique identity. Every time there is a change in the value of a column, then I have to change it.

Below is the structure for the history table.

frame of history table

Now in our system two forms Are together with numbers 2 and 4. Then the result history data should look like this.

Results from the history table for Form # 2 and 4>

In MSSQL you can use the function to get the previous value. With the CT (SELECT ID, number as subdimedge, 'zodiac' as the field, leg (zodiac) over (based on old number id) as the old value, The amount of new value in the form of T) SELECT * is whistle where there is no order by Old Volume, IDID ID Another method of using the ROW_NUMBER () function to add an existing record to the previous record is so that you Receive all the values ​​from the previous record Enable:

P>

 with  in the form of whistle (SELECT T. *, ROW_NUMBER ()) (according to ID DESC as Romania ) Part whistle *, CT2 CT2 on the CT.Number = CT2 as the whistle added whistle from the old voltage. Number and CT.RowNum + 1 = CT2 RowNum command CT.number, CT.ID   



Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -