问题
At the moment I have a column in a table with this information:
For example:
00:11:35
00:20:53
00:17:52
00:06:41
And I need to display the average of that time.
These times would give an average of 00:14:15.
How to do that?
Ah, I'm trying to display this in Metabase, so I'd need a conversion form where after averaging the time it was converted to string.
So maybe it's not that simple.
The structure of field is:
Table Field: tma (type time)
回答1:
Below is for BigQuery Standard SQL
#standardSQL
WITH `project.dataset.table` AS (
SELECT TIME '00:11:35' tma UNION ALL
SELECT '00:20:53' UNION ALL
SELECT '00:17:52' UNION ALL
SELECT '00:06:41'
)
SELECT
TIME_ADD(TIME '00:00:00', INTERVAL CAST(AVG(TIME_DIFF(tma, TIME '00:00:00', SECOND)) AS INT64) SECOND) average_time,
FORMAT_TIME('%T', TIME_ADD(TIME '00:00:00', INTERVAL CAST(AVG(TIME_DIFF(tma, TIME '00:00:00', SECOND)) AS INT64) SECOND)) average_time_as_string
FROM `project.dataset.table`
with result
Row average_time average_time_as_string
1 00:14:15 00:14:15
来源:https://stackoverflow.com/questions/52975901/how-do-i-calculate-an-average-time-using-standardsql