使用sql计算类型时间的总和 [英] calculate a sum of type time using sql

查看:32
本文介绍了使用sql计算类型时间的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算名为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.

这篇关于使用sql计算类型时间的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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