【问题标题】:Is there a way to calculate time differences in MySQL using one select有没有一种方法可以使用一个选择来计算 MySQL 中的时间差
【发布时间】:2009-02-25 16:35:19
【问题描述】:

我有一个包含以下内容的表格:

name    type
id    : INT
date1 : DATETIME
date2 : DATETIME

我需要计算 date2 和 date1 之间的差异。

这可以使用 MySQL 中的 TIMEDIFF 函数来实现。

但是,有没有办法使用一个选择而不是使用 2 个辅助选择来获取 TIMEDIFF(date2,date1) 的结果:

select TIMEDIFF( (select date2 from example_table where id=1) , (select date1 from example_table where id=1) );

【问题讨论】:

    标签: mysql


    【解决方案1】:
    select TIMEDIFF( date2 ,date1) from example_table where id=1;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-21
      相关资源
      最近更新 更多