我有两个与外键关系链接的表。两个表都有创建日期列。如何找到时差为 5 分钟加或减的所有匹配行。
问问题
120 次
2 回答
1
您需要使用 timestampdiff 函数和 abs 函数,如下所示:
select * from table1 a, table2 b where a.ID=b.FOREIGNID and ABS(TIMESTAMPDIFF(MINUTE,a.CREATEDDATE,b.CREATEDDATE)) > 5
两个函数的文档:
http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_abs
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampdiff
于 2013-01-28T14:50:08.417 回答
0
那应该行得通。还是双方都需要?
SELECT *
FROM tableA a
JOIN tableB b
ON a.keyInfo = b.keyInfo
AND b.created BETWEEN a.created - 5/(24*60) AND a.created + 5/(24*60)
于 2013-01-28T14:50:51.000 回答