使用sql计算类型时间的总和

2021-11-20 00:00:00 sql mysql

如何计算名为timeSpent"的冒号的时间总和,格式如下:HH:mm在 SQL 中?我正在使用 MySQL.

我的专栏类型是时间.

它有这个结构

<前>时间从 10:00:00 12:00:00 02:00:00时间至 08:00:00 09:15:00 01:15:00所花费的时间总时间 03:15:00

解决方案

SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `timeSpent` ) ) ) AS timeSum从你的表名

这对我有用.希望这会有所帮助.

How to caculate sum of times of my colonne called "timeSpent" having this format: HH:mm in SQL? I am using MySQL.

the type of my column is Time.

it has this structure

TimeFrom like  10:00:00           12:00:00     02:00:00
TimeUntil      08:00:00           09:15:00     01:15:00
Time spent      

total time 03:15:00

解决方案

SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `timeSpent` ) ) ) AS timeSum  
FROM YourTableName  

This worked for me. Hope this helps.

相关文章