有没有一种方法可以使用一次选择来计算MySQL中的时差 [英] Is there a way to calculate time differences in MySQL using one select

查看:53
本文介绍了有没有一种方法可以使用一次选择来计算MySQL中的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a table containing the following:

name    type
id    : INT
date1 : DATETIME
date2 : DATETIME

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

And I need to calculate the difference between date2 and date1.

可以使用在MySQL中使用TIMEDIFF 函数.

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

However, is there a way to get the result of TIMEDIFF(date2,date1) using one select, and not using 2 helper selects:

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

推荐答案

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

这篇关于有没有一种方法可以使用一次选择来计算MySQL中的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆