1

在大查询中将时间连接在一起,但它不允许我使用它。

IF(CAST(TRUNC(timestart/60) AS INT64) <= 12,
CAST(TRUNC(timestart/60) AS INT64),
CAST(TRUNC(timestart/60) AS INT64) - 12) AS hour,
MOD(timestart, 60) AS minutes,
IF(CAST(TRUNC(timestart/60) AS INT64) < 12,
'AM',
'PM') AS timetype,

康卡特

concat(IF(CAST(TRUNC(timestart/60) AS INT64) <= 12,
CAST(TRUNC(timestart/60) AS INT64),
CAST(TRUNC(timestart/60) AS INT64) - 12)+':'+
MOD(timestart, 60)) AS tbegin,

错误:对于参数类型:INT64、STRING 的运算符 + 没有匹配的签名。支持的签名:INT64 + INT64;浮点64 + 浮点64;NUMERIC + NUMERIC 在 [5:10]

如何在 bigquery 中连接时间

Row scheduleid  timestart   timeduration    hour    minutes timetype     
1   35319        600          60             10         0   AM   
2   69682        960           30            4          0   PM   
3   186862      1020          30            5          0    PM   
4   346371      1020          60            5           0   PM
4

1 回答 1

1

以下是 BigQuery 标准 SQL

#standardSQL
SELECT 
  FORMAT_TIME('%r', TIME(DIV(timestart, 60), MOD(timestart, 60), 0)) AS tbegin
FROM `project.dataset.table`  

您可以使用您问题中的示例数据进行测试,使用它,如下例所示

#standardSQL
WITH `project.dataset.table` AS (
  SELECT 35319 scheduleid, 600 timestart, 60 timeduration, 10 hour, 0 minutes, 'AM' timetype UNION ALL
  SELECT 69682, 960, 30, 4, 0, 'PM' UNION ALL
  SELECT 186862, 1020, 30, 5, 0, 'PM' UNION ALL
  SELECT 346371, 1020, 60, 5, 0, 'PM' 
)
SELECT *,
  FORMAT_TIME('%r', TIME(DIV(timestart, 60), MOD(timestart, 60), 0)) AS tbegin
FROM `project.dataset.table`   

结果

Row scheduleid  timestart   timeduration    hour    minutes timetype    tbegin   
1   35319       600         60              10      0       AM          10:00:00 AM  
2   69682       960         30              4       0       PM          04:00:00 PM  
3   186862      1020        30              5       0       PM          05:00:00 PM  
4   346371      1020        60              5       0       PM          05:00:00 PM  

更新:

解决 24:00:00 问题

#standardSQL
SELECT 
  TIME(TIMESTAMP_ADD(TIMESTAMP(CURRENT_DATE()), INTERVAL timestart MINUTE)) AS tbegin
FROM `project.dataset.table`  
于 2019-01-28T20:01:03.417 回答