我想选择下一个非空引导场景_时间戳。我尝试了以下方法,但收到“从 BOOL 到 TIMESTAMP 的转换无效”错误。
FORMAT_TIMESTAMP(
'%Y-%m-%d %H:%M:%E6S',
CAST(
CONCAT
(
CAST(date AS STRING),
' ',
FORMAT_TIMESTAMP
('%H:%M:%E6S', cast(lead(scenario_timestamp is not null ) OVER (ORDER BY date DESC ) as timestamp
)
)
) AS TIMESTAMP
)
)
这有效:
SELECT
date,
name,
CASE
WHEN scenario_timestamp IS NOT NULL THEN scenario_timestamp
ELSE FORMAT_TIMESTAMP (
'%Y-%m-%d %H:%M:%E6S',
CAST(
CONCAT (
CAST(date AS STRING),
' ',
FORMAT_TIMESTAMP (
'%H:%M:%E6S',
CAST(
(
SELECT
MIN(sub.scenario_timestamp)
FROM
dates_combine AS sub
WHERE
sub.date > main.date
AND sub.scenario_timestamp IS NOT NULL
) AS TIMESTAMP
)
)
) AS TIMESTAMP
)
)
END AS scenario_timestamp
FROM
dates_combine AS main