简体   繁体   English

在SQL查询中平均时间戳

[英]Averaging timestamps in SQL query

Simple question really.... 确实是个简单的问题。

How do I average timestamps in an SQL query?? 如何在SQL查询中平均时间戳?

The column format is set to TIME 列格式设置为TIME

and the values are as follows. 值如下。

00:01:32
00:02:22
00:02:14
00:01:35
00:01:19

I simply want to add up the minutes and seconds, and calculate the average time spent on a task 我只想将分钟和秒加起来,并计算在一项任务上花费的平均时间

So in this instance it would be 542 seconds / 5 tasks for an average of 108.4 seconds or 00:01:48 per task. 因此,在这种情况下,这将是542秒/ 5个任务,平均每个任务108.4秒或00:01:48。

It seems so simple yet I cannot for the life of me find any answers. 看起来很简单,但我终生无法找到任何答案。 Everything I've found so far uses DATETIME or TIMESTAMP fields. 到目前为止,我发现的所有内容都使用DATETIME或TIMESTAMP字段。 Im simply using TIME. 我只是在使用时间。

Assuming MySQL: 假设MySQL:

SELECT AVG(TIME_TO_SEC(your_column)) AS average_seconds,
SEC_TO_TIME(AVG(TIME_TO_SEC(your_column))) AS average_time
FROM your_table;
  • read more about the functions used here 在此处阅读有关使用的功能的更多信息

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

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