Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Syntax Help Needed - Time Diffs
Message
From
08/03/2002 15:40:38
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00626592
Message ID:
00630383
Views:
30
>>>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?
>>
>>
select * ;
>>from logtable lt ;
>>where lt.timestamp-lnGap > ;
>>(select max(timestamp) from logtable where timestamp < lt.timestamp)
>
>Thanks! I now want to add another column, which shows how long it actually took. How can I add that calculated column?

I can't think of a way of doing this without an UDF (UPDATE does not allow sub-queries):
update logtable set gap = findgap(timestamp)

function findgap
lparameters tm
local array laQry(1)

select max(timestamp) from logtable where timestamp < tm into array laQry
if empty(laQry(1))
	laQry(1) = tm
endif

return tm-laQry(1)
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform