我有一张这样的桌子
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中做到这一点..
select *,TIMESTAMPDIFF(SECOND,t1.AT_TIME,t2.AT_TIME) AS diff from tps_info t1 , tps_info t2 having diff='60'
终于我做到了,就这样——
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
看演示
注意:它工作正常,除了最后一条记录没有被检索。
结果相同
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 ) )
select * from TPS_INFO where TIMESTAMPDIFF(SECOND, AT_TIME,NOW()) < 60