【问题标题】:DataStudio and SQL change time format from numbers to hh:mm:ssDataStudio 和 SQL 将时间格式从数字更改为 hh:mm:ss
【发布时间】:2021-09-04 15:28:06
【问题描述】:

我想在 Datastudio(或 SQL)中将度量格式从浮点数更改为 HH:MM:SS。

例如:

Float HH:MM:SS
75 00:01:15
90 00:01:30
79.5 00:01:20

等等……

【问题讨论】:

    标签: sql datetime google-bigquery dashboard google-data-studio


    【解决方案1】:

    如果您输入的秒数适合 24 小时 - 所以可以显示为时间类型 - 在下面使用

    select format_timestamp('%T', timestamp_seconds(cast(seconds as int64))) time   
    

    如果应用于您问题中的样本数据 - 输出是

    如果输入秒数超过 24 小时 - 您可以在下面使用 - 它为您提供 H*:MM:SS 格式的字符串表示

    select format('%i:%s',
        div(cast(seconds as int64), 3600),
        format_timestamp('%M:%S', timestamp_seconds(mod(cast(seconds as int64), 3600)))
      ) time
    

    输出为

    【讨论】:

      猜你喜欢
      • 2020-09-27
      • 2013-09-09
      • 2017-07-21
      • 1970-01-01
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多