简体   繁体   English

如何在 MySQL 中存储派生列

[英]How to store Derived Column in MySQL

I have a table A which have Start_time and End_time as columns, i am calculating the difference of these two columns as我有一个表 A ,其中有Start_timeEnd_time作为列,我正在计算这两列的差异

Select timediff(End_time, Start_time) as TF from A

Now i want to sum of all time periods present ln TF column.现在我想对 ln TF列中存在的所有时间段求和。

I searched alot but could not found anything related to it我搜索了很多,但找不到任何与之相关的内容

Timediff() will give you result in HH:MM:SS format. Timediff()将为您提供HH:MM:SS格式的结果。 In order to SUM() them up, you need to first convert them into numbers (in this case, seconds);为了将它们SUM()起来,您需要先将它们转换为数字(在本例中为秒); add them up using SUM() ;使用SUM()将它们相加; and then convert them back to HH:MM:SS format:然后将它们转换回HH:MM:SS格式:

SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( TIMEDIFF(End_time, Start_time) ) ) ) 
FROM A

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM