yol*_*ola 3 sql type-conversion google-bigquery
我在 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
Run Code Online (Sandbox Code Playgroud)
如果适用于您的问题中的样本数据,如
with `project.dataset.table` AS (
select 100000 seconds union all
select 200000 union all
select 300000
)
Run Code Online (Sandbox Code Playgroud)
输出是
| 归档时间: |
|
| 查看次数: |
9926 次 |
| 最近记录: |