Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须在来自两个不同表的两个字段之间进行减法运算,其中一个字段是日期时间,另一个字段是时间戳。
实现这一目标的最佳方法是什么?
首先转换为unix时间戳?
就像是:
select UNIX_TIMESTAMP(t1.col1) - UNIX_TIMESTAMP(t2.col2) from t1, t2 ...
TIMESTAMPDIFF是迄今为止最通用的选择。
TIMESTAMPDIFF
select timestampdiff(SECOND, t1.col1, t2.col2);
在小提琴中看到它