答案 0 :(得分:0)
我是在t-sql中完成的,但我认为在mysql中翻译并不是那么难。 假设timestamp列是datetime类型,则此查询执行您要求的内容(我在t-sql中测试它,因此我创建了一个表变量,您必须使用您的表):
declare @table table (userid int, input varchar(50),timestmp datetime)
insert into @table values(1,'hy','1/19/2017 12:00')
insert into @table values(2,'by','1/19/2017 12:00')
insert into @table values(1,'hy2','1/19/2017 12:01')
insert into @table values(2,'by2','1/19/2017 12:01')
insert into @table values(3,'why','1/19/2017 12:01')
select t1.userid,t1.input,t2.input from @table t1 inner join @table t2 on t1.userid=t2.userid and t1.timestmp=DATEADD(mi,-1,t2.timestmp)
答案 1 :(得分:0)
尝试此查询,它会给出预期的输出。
SELECT t1.userid,t1.input,t2.input
FROM test_table t1
INNER JOIN test_table t2
ON TIMESTAMPDIFF(MINUTE,t1.timestmp,t2.timestmp) <= 1
AND t1.userid = t2.userid
注意:将table_name替换为test_table
如有任何疑问,请询问。