时间戳字段是 DATETIME
列,格式类似于 2012-03-19 00:23:14
。如何比较两行时间戳并找到较大的那一行?我正在使用的下面的查询不起作用。
UPDATE report 1 status = 'time is larger' WHERE EXISTS
(SELECT ip_src, layer4_sport, timestamp FROM
(SELECT ip_src, layer4_sport, timestamp from report 1) AS tmpb
WHERE report 1.layer4_sport = tmpb.layer4_sport
AND report 1.ip_src = tmpb.ip_src
AND report 1.timestamp > tmpb.timestamp
GROUP BY ip_src, layer4_sport, timestamp HAVING COUNT(*) = 2)
最佳答案
您可以尝试使用 if 语句来验证 A 时间戳是否大于 B 时间戳。
select if(UNIX_TIMESTAMP('2009-02-01 00:00:00') > UNIX_TIMESTAMP('2009-01-01 00:00:00'), true, false)
关于mysql - 如何比较 MySql 中的两个时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10384443/