Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Processing with the previous rec in SQL
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00272151
Message ID:
00272381
Vues:
34
>>
>>I have a log table from which I'm trying to
>>produce a summary table (recs processed, seconds,
>>recs/second).  To do this I (obviously) need
>>the value of the previous record count and
>>timestamp.
>>
>>Is there a way of doing this with SQL, or will
>>I have to code a good old fashioned loop?
>>
>>advTHANKSance...
>>
>>   ...kt
>>
>
>I'm not clear on what your table looks like. The general way to compare values from adjacent records is to get all the records numbered, then make an offset self-join, sort of like this:
>
>* get 'em in order
>SELECT * FROM yourtable INTO CURSOR curs1 ORDER BY whatever
>* number 'em
>SELECT *, RECNO() AS cursnums FROM curs1 INTO CURSOR curs2
>* offset self-join
>SELECT curs2a.field1, curs2a.field2, curs2a.fieldtocompare AS fielda, ... curs2b.fieldtocompare AS fieldb FROM curs2 AS curs2a INNER JOIN curs2 AS curs2b ON curs2a.cursnums = curs2b.cursnums + 1 INTO CURSOR curs3
>* now you can compare the records
>SELECT field1, field2, ... , youroperation(fielda,fieldb) FROM curs3
>
>Your own SQL may need grouping or whatever.

A very creative use of SQL. It may be easier, without the dreaded loop that Keith is trying to avoid, to:

USE sometable IN 0 ALIAS use1
USE sometable AGAIN IN 0 ALIAS use2
SELECT use1
SET RELATION TO RECNO() + 1 INTO use2
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform