我有一张这样的表
CREATE TABLE `TPS_INFO` (
`TPS` INT(10) NULL DEFAULT NULL,
`AT_TIME` TIMESTAMP NOT NULL
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)
我想选择TPS值和时间戳,以便在1分钟内选择时间戳。
我如何在mysql中执行此操作..
答案 0 :(得分:0)
select *,TIMESTAMPDIFF(SECOND,t1.AT_TIME,t2.AT_TIME) AS diff from tps_info t1 , tps_info t2 having diff='60'
答案 1 :(得分:-1)
最后我做到了,在这里 -
Select m.tps,m.at_time from TPS_info m, tps_info c
where (date_add(m.at_time, INTERVAL 1 MINUTE) = c.at_time) OR
(date_add(m.at_time, INTERVAL -1 MINUTE) = c.at_time)
group by m.at_time
order by m.at_time
最初我尝试,
Select m.tps,m.at_time from TPS_info m, tps_info c
where date_add(m.at_time, INTERVAL 1 MINUTE) = c.at_time
请参阅DEMO
注意:它的工作正常,但最后一条记录没有被检索。
与
相同的结果Select m.tps,m.at_time from TPS_info m, tps_info c
where 60 = TIME_TO_SEC( TIMEDIFF( m.at_time, c.at_time ) )
答案 2 :(得分:-1)
select * from TPS_INFO where TIMESTAMPDIFF(SECOND, AT_TIME,NOW()) < 60