所以我正在使用 Google Big Query,并且我想找到整个专栏的平均时间。整个列的时间格式为 hh:mm:ss,例如 00:19:00。
select
AVG(ride_length) AS average_duration
FROM `casestudy1-361603.project.DecData`
但是,出现错误:“参数类型的聚合函数 AVG 没有匹配的签名:STRING”。
这就是该列的外观 https://i.stack.imgur.com/0aKVA.png
将字符串投射到区间数据类型 https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#interval_type并执行平均:
select avg(cast(t as interval)) as agg
from unnest(['10:20:30', '30:40:50']) as t
returns
UPD:如果你想提取结果的特定部分,你可以使用justify_interval https://cloud.google.com/bigquery/docs/reference/standard-sql/interval_functions#justify_interval将间隔标准化为标准日持续时间(24 小时)并使用extract功能 https://cloud.google.com/bigquery/docs/reference/standard-sql/interval_functions#extract提取部分。
with src as (
select avg(cast(t as interval)) as agg
from unnest(['70:20:30', '40:40:50']) as t
)
select
src.agg,
justify_interval(agg) as normalized_,
extract(hour from justify_interval(agg)) as h
from src
agg |
normalized_ |
h |
0-0 0 55:30:40 |
0-0 2 7:30:40 |
7 |
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)