Bigquery 的连接时间 hr:min
Concat time in hr:min for Bigquery
想在大查询中将时间连接在一起,但它不允许我使用它。
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
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; FLOAT64 + FLOAT64; [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
以下适用于 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
Update:
解决24:00:00问题
#standardSQL
SELECT
TIME(TIMESTAMP_ADD(TIMESTAMP(CURRENT_DATE()), INTERVAL timestart MINUTE)) AS tbegin
FROM `project.dataset.table`
想在大查询中将时间连接在一起,但它不允许我使用它。
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
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; FLOAT64 + FLOAT64; [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
以下适用于 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
Update:
解决24:00:00问题
#standardSQL
SELECT
TIME(TIMESTAMP_ADD(TIMESTAMP(CURRENT_DATE()), INTERVAL timestart MINUTE)) AS tbegin
FROM `project.dataset.table`