I need to write a query that will get the value of a previous records and add it to the current record.
In detail:
I have a table (Table1) that contains PolicyNum, RecordID, and SequenceID
PolicyNum RecordID SequenceID
123456 456 0
123456 456 0
123456 789 1
123456 789 1
123456 123 2
123456 123 2
I have another table (Table2) with RecordID, CompanyID, Total
RecordID CompanyID Total
456 4321 500
789 4321 700
456 8765 600
789 8765 800
123 4321 900
123 8765 1000
I created a query on a inner join of the two tables on RecordID to get this.
PolicyID RecordID CompanyID SequenceID Total
12345 456 4321 0 500
12345 456 8765 0 600
12345 789 4321 1 700
12345 789 8765 1 800
12345 123 4321 2 900
12345 123 8765 2 1000
Now the big question:
If all I have is a RecordID, how can I get the Total's of the Record's with the previous SequenceID
ie
I have RecordID 123
I need Total's from the records with SequenceID = (SequenceID) -1 (700, 800)
Then I need to add the previous amount to the current amounts (900, 1000).
RecordID CompanyID Total
123 4321 1600
123 8765 1800
Any suggestions will be helpful.
Thanks