MySQL Forums
Forum List  »  Newbie

Re: shortest time between the entries of each user
Posted by: Peter Brawley
Date: December 03, 2014 10:33AM

> I am not sure if it is allowed here to ask help concerning a concrete query

Sure is.

> query which shows for each users, which was the shortest time between their entries

One way assuming a table t(t timestamp, user int) ...

select t.user, min(diff)
from (
  select t.user, unix_timestamp(tnext.t)-unix_timestamp(t.t) as diff
  from t 
  join t as tnext on t.user=tnext.user and t.t<tnext.t
  group by t.user, t.t
) as t
group by user;

Options: ReplyQuote


Subject
Written By
Posted
Re: shortest time between the entries of each user
December 03, 2014 10:33AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.