Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
How to check previous record value
Versions des environnements
Hi All;
I have a several hundreds thousands records in a table which I need to compare the closing value of each record with the previous one.
I used the following code
Option 1
go top
scan
nVal1 = nClsVal
skip
nVal2 = nClsVal
skip -1
rest of code
endscan
too slow.
option2
select A.*, 000000000 as nRecNo from table1 to Cursor cTbl_1 readwrite
then replace the nRecNO with Recno() all
select A.*, 000000000 as nRecNo from table1 to Cursor cTbl_2 readwrite
then replace the nRecNO with Recno()-1 all
Finally
select a.*, b.nClsVal as nPrvVal ;
from cTbl_1 a, cTbl_2 b ;
where a.nRecNo = b.nRecNo ;
into cursor cTmp
This is far more faster than option 1 but done in 3 sql select statement.
Is there is any suggestion for a more elegent way
Thanks all
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement