Forum: Ruby on Rails SELF JOIN to compare two successive rows

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Martin (Guest)
on 2009-02-24 19:00
(Received via mailing list)
Hi,

I have a DB that different computers add entries to roughly every 10
seconds.
Later on I want to check "gaps", when two entries from one computer
are further than 20 seconds apart and other things that have to do
with comparing two rows.
In MYSQL I added a new column "succ_id" for this which I increse on a
per-computer basis.
I did this to be able to find two successive rows via a JOIN-query in
MYSQL.
So I would find the rows by
SELECT t1.*, t2.t* FROM computerdata t1 inner join computerdata t2 on
t1.succ_id=t2.succ_id-1 and t1.seconds<t2.seconds-20;
Now I'm trying to figure out how to do this "the rails way".
The act as tree is a little bit overweighted I think and I would need
to restructure my DB as I don't have the references to the have
antecessor.
Can anybody give me a hint?
Thanks in advance,

Martin
This topic is locked and can not be replied to.