The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Invoke: SQL gurus. by Tomo2008-09-15 05:52:04
  You can't with a straightforward SELECT I don't by sazzer 2008-09-15 06:00:45
think. Select statements operate on a row-by-row basis, with no regard to any other rows in the dataset. Unless you can write a subselect to extract the details of the previous row - which is a possability depending on your data and query - then you might need to go for cursors instead, and I'm not sure if Mysql supports those...

Without knowing your data at all - so you might have to adapt this heavilly - something like this *might* work:

SELECT Object_Id, Event, T1, T2, DATEDIFF(T1, T2) FROM (
SELECT
Object_Id,
Event,
Timestamp AS T1,
(SELECT
Timestamp
FROM Data d2
WHERE d2.Object_Id = d1.Object_Id
AND d2.Event_Type = d1.Event_Type
AND d2.Timestamp < d1.Timestamp
ORDER BY Timestamp DESC
LIMIT 1) AS T2
FROM Data d1)

Even if that does work, cursors or similer will be much much better performance-wise if this is going to be a common thing and not just a one-off...
[ Reply ]

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)