简体   繁体   中英

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

Select timediff(End_time, Start_time) as TF from A

Now i want to sum of all time periods present ln TF column.

I searched alot but could not found anything related to it

Timediff() will give you result in HH:MM:SS format. In order to SUM() them up, you need to first convert them into numbers (in this case, seconds); add them up using SUM() ; and then convert them back to HH:MM:SS format:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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