Mysql: Find rows, where timestamp difference is less than x

前端 未结 3 1814
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 07:35

I\'ve got table structure as follows:

Field       Type
id              int(11)      AI
user            varchar(64)
date            timestamp
key             int         


        
3条回答
  •  执念已碎
    2021-01-24 08:13

    try this :-

    select t1.user, t1.date d1,t2.date d2 ,t1.date-t2.date
      from  (select @val:=@val+1 rowid,user,  date
               from mytable,(select @val:=0) a
           order by user,date) t1,
    
            (select @val1:=@val1+1 rowid,user,  date
               from mytable,(select @val1:=1) b
           order by user,date) t2
    
     where t1.rowid = t2.rowid
       and t1.user = t2.user
       and t1.date-t2.date < 1300;
    

    see DEMO

提交回复
热议问题