Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Processing with the previous rec in SQL
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00272151
Message ID:
00272381
Views:
32
>>
>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform