我在Bigquery中转换秒时遇到麻烦,在Bigquery中是否有将秒转换为小时:分钟:秒格式的功能?我已经尝试过该TIMESTAMP_SECONDS()
功能,但它还会返回一些日期,如果小时数超过23,则无法使用它,例如:
秒= 100000
结果= 27:46:40
或作为1天3小时46分钟40秒
我也希望它在时间戳数据类型中,以便我可以将其升序或降序。
以下是BigQuery标准SQL
#standardSQL
select seconds,
regexp_replace(
cast(time(ts) as string),
r'^\d\d',
cast(extract(hour from time(ts)) + 24 * unix_date(date(ts)) as string)
) as option1,
format(
'%i day %i hour %i minute %i second',
unix_date(date(ts)),
extract(hour from time(ts)),
extract(minute from time(ts)),
extract(second from time(ts))
) as option2
from `project.dataset.table`,
unnest([timestamp_seconds(seconds)]) ts
是否适用于您的问题中的样本数据,如
with `project.dataset.table` AS (
select 100000 seconds union all
select 200000 union all
select 300000
)
输出是
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句