Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Query for returning "nearby" rows?
August 30, 2006, 8:54 pm
rate this thread
SELECT User,Activity,Timestamp FROM `table` WHERE Activity = 'TEST'
So the query tells us who and when did activity "TEST."
Is there another query I could write that would tell me who performed a
test and what activities they performed within 10 minutes of test?
I'm figuring it's possible with a self-join or subquery, but I can't
figure it out.
Re: Query for returning "nearby" rows?
Here a possible solutions:
SELECT t1.User, t1.Activity, t1.Timestamp
FROM `table` AS t1 JOIN `table` AS t2
ON t1.User = t2.User AND
(t2.Timestamp - INTERVAL 10 MINUTE) AND
(t2.Timestamp + INTERVAL 10 MINUTE)
WHERE t2.Activity = 'TEST';
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum