Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Syntax Help Needed - Time Diffs
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00626592
Message ID:
00627380
Vues:
20
>I have a log table with 4000 rows, each with a datetime stamp of when an action occured. I am trying to do a "date diff" between each row, and only show those rows that have taken longer than n seconds. I'm trying to get away from doing a table scan, does anyone have any help for doing it with pure SQL?

Steve,

Taking into account the deleted records and any order that may be meaningful to you
local sCollate
sCollate = set('Collate')

set Collate to 'Machine'

select * ;
    from Table ;
    into Cursor CursorTable ;
    where ( SomeCondition ) ;
    order by SomeOrder

select *, ;
       recno() as r1 ;
    from CursorTable ;
    into Cursor x1

select x1
index on bintoc(r1+1) tag r1

select *, ;
       recno() as r2 ;
    from CursorTable ;
    into Cursor x2

select x2
index on bintoc(r2) tag r2

select x2.*, ;
       x2.DateTimeField - x1.DateTimeField as SecondTaken ;
    from x1, x2 ;
    where   ( bintoc(r2) == bintoc(r1+1) ) ;
        and (  (x2.DateTimeField - x1.DateTimeField) > n ) 

set Collate to (sCollate)
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform